3

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.

Community
  • 1
  • 1
craigh
  • 1,909
  • 1
  • 11
  • 24
  • 1
    Don't do that. There was a good reason, why such stuff was removed in symfony 2. – Emii Khaos May 28 '15 at 20:21
  • 1
    @Paziツ Does that mean it was possible in Symfony 1? Do you have any reference of this feature and / or why it was removed? – Christian May 28 '15 at 21:49
  • I'm not working with Symfony 1 and never did. As I mentioned, I am trying to use Symfony to replicate a feature in a **different/old** framework. – craigh May 29 '15 at 02:20
  • You could write a Symfony exception listener and listen for the NotFoundHttpException, and then do whatever you are trying to do. – Gerry May 29 '15 at 08:47
  • Let me get this straight, instead of using the standard way in Symfony that is to create an action in a controller and simply associate a route to it, you want to: listen to an exception when a route you did not associate to an action in a controller get thrown so you can then associate it to a an action in a controller to call it? Maybe some words on the big picture are required in this case. To translate your old framework routes for Symfony it might be just about setting a couple of rewrite in your favourite web server. – ggioffreda May 29 '15 at 10:03
  • you could write an action that takes the parameters and looks up a sf route with it. But that can only be a temporary solution until you actually manage to take the sf routes directly. Have a loog at SF2s HttpFoundation/Request object, where you can extract all your parameters and build routes from it... This seems very wrong though. Why not app.php/foo/bar/zip ? – DerStoffel May 29 '15 at 14:09

1 Answers1

1

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.

craigh
  • 1,909
  • 1
  • 11
  • 24