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.
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.
