phpsymfonyrouteszikula

Symfony Controller magic method?


I am trying to use Symfony to replicate behavior in an existing Framework (zikula). This framework is extensible using modules which are basically extended symphony bundles. The old framework had urls like so

index.php?module=foo&type=bar&func=zip

which in symfony speak roughly translates to

index.php?bundle=foo&controller=bar&method=zip

The framework has an AbstractController which has a magic method like:

public function __call($method, $args)
{
    $event = new \Zikula\Core\Event\GenericEvent($this, array('method' => $method, 'args' => $args));
    $this->eventManager->dispatch('controller.method_not_found', $event);
    if ($event->isPropagationStopped()) {
        return $event->getData();
    }
}

so, if you created a url with a method that didn't exist in the bundle, you could create a listener to capture it and send a response that looks like and behaves like it came from the specified bundle. We use this to call module services that are available to all modules and provided in a separate module but look like they are served by the 'host' module.

Now I am trying to replicates this using symfony and routing.

the first problem is generating a route that doesn't technically exist. Is this possible?

The second problem is capturing the RouteNotFoundException (which I know how to do, we already have listeners for other exceptions).

The last problem is making it appear that the bundle is serving up the response when it is actually being served by an event listener (or something else). This last part is important because other content in the response needs to come from the module/bundle.

I have tried changing the current listener to a controller, and also tried adding a method to our extension of symfony's AbstractController, but haven't yet achieved what I am hoping to achieve. I'm hoping for some suggestions on new ideas or methods to try.


Solution

  • I gave up trying to replicate the exact behavior as it seems impossible (it is also pretty difficult to describe). So I have resorted to a normal controller with standard route, but I found a way to make it appear to belong to the original 'host' module. Thanks to Gerry, ggioffreda and DerStoffel for offering ideas.