I'm making a custom user bundle, allowing for defining multiple user types, with their own repositories, managers, providers etc. So, I decided, instead of creating the limited set of controllers, to create a controller factory, which would produce controllers based on the defined user types and configuration. But this raises the important question - where, and how should those factories operate?
Now, mind you that it doesn't suffice to create a controller in the factory, we also have to set up all routes for it, somewhere.
The question is - what would be the best architecture for this?
When it comes to choosing a layer where I will place my code, I was considering, among others:
Loading factory definitions in Extension's
load
method, and creating all of the controllers there. The problem: Router is not available there, because it happens before container building, so I couldn't create routes in the same place.So, maybe in the compiler pass? However the compiler pass doesn't have access to the configuration. I mean in fact, it has, if I will just load the configuration and process it manually, but I'm still not sure if this is a good place, but I'm leaning towards this solution right now.
When it comes to creating routes:
Should I place routes creation logic in the controller factory? But I'm creating controllers as services and the factory doesn't have access to the serviceId of the created controller, and serviceId is required for creating a route, so nope.
In the controller itself? I mean, that's how annotation routes work, so it might be viable. Controller would have to implement something like my own
ControllerInterface
with the methodgetRoutes
, and the external service/compiler pass would need to create a controller as a service first, and then get routes from the said controller, modify them, so they would refer this controller's serviceId and add them to the router... regardless of how messy this looks like.Is there any other option?
There is a considerable lack of information regarding this particular pattern - factory of controllers :).