0
votes

I am building an app with Symfony 4 that can be extended by plugins. Plugins are essentially bundles, but they are just dropped into a folder and don't have to be activated (for example, in config/bundles.php or in config/routes/).

In order for plugins to register routes automatically, I have CMF chain router override the default symfony @router service. Each plugin can then have a service tagged router, which the chain router adds to the chain. This part works.

In order to make it easier for plugins to register routes, the core app provides an AnnotationRouter class, which takes a path to look for annotated controllers in. The plugins would then register a service like this:

sample_plugin.router:
    class: MyApp\Routing\AnnotationRouter
    arguments: ['@service_container', '@@SamplePlugin/Controller']
    tags:
      - { name: router, priority: 20 }

However, these routes behave very strangely. In fact, they only work on the first request after clearing the cache! All subsequent requests return 404 errors. This is what the 'Routing' tab in the symfony profiler looks like.

Screenshot of the symfony profiler on subsequent requests

On the top it says it doesn't match a route, but on the bottom it matches! I don't know what to make of this.

Also, bin/console router:match /test2 matches the route and bin/console debug:router lists the route. All the routes of the default symfony router (which is the only other router in the chain besides the plugin's router) work as they should.

Interestingly, all of this has worked before, when still using symfony 3.

1

1 Answers

0
votes

Ok, turns out this is not an issue with CMF Routing chain router after all, but rather with the implementation of the actual router.

My router implementation is as described in this question. The problem had to do with Doctrine's annotation reader and annotation autoloading. I ended up installing indigophp/doctrine-annotation-autoload, which apparently is only a workaround though.

See also Autoloading annotation classes on GitHub.