I need to implement various meta data attributes for each route, and one idea I have is to apply the attributes directly onto each route, for an external meta data listener to make use of.
For example, the listener would use the service (
value: 'Example | %%value_to_be_resolved%% | %default_title_suffix%'
Here's the solution I ended up with:
example_route: path: /blah/blah defaults: _controller: MyBundle:MyController:index meta: title: resolver: '@example_title_resolver' value: 'Example | %%value_to_be_resolved%% | %default_title_suffix%'
Listener 1 - Service resolver. Invoked immediately after the RouterListener with a priority of 33 or higher, at this point the route params have been applied onto the request (@see https://github.com/symfony/http-kernel/blob/master/EventListener/RouterListener.php#L97).
The listener, attached to the
kernel.request event inspected the request params, and resolved any services (string values prefixed with @) against the service container injected into the listener.
Listener 2 - Meta data listener. At this point, everything on the route/request has been resolved into services already. This decouples concerns, and allows further unrelated listeners to benefit from the ability to talk to services available directly on the request.
In this example, the meta data listener would look for specific params (resolved services) on the request. These objects would be used to resolve meta data values for example. A common mechanism would then be required to make this data available to the view.
Resolver classes Responsible in turning a given template string into the final value. Invoked by the meta data listener above.
I'm going to roll with this for now as the advantages are appealing. I'll check in when the solution no longer fits.