This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Router related classes

Discuss Symfony 2 bundles here

Router related classes

by Mikz » Sun May 11, 2014 1:26 pm

Hi!

I'd like to extend base router functionality to support more complex url parameters. In order to do that, I've found that I can override following configuration parameters:
controller_resolver.class
router.options.generator_class
router.options.generator_base_class

with my own classes extending symfony2 native ones.
It's great that I can do something like that just using configuration parameters and overriding doGetArguments and doGenerate methods to handle more complex arguments and pass the rest to native Symfony2 code.
Unfortunately, both of those classes needs to check action annotations for my custom annotation configuring options for whole process to be customizable. But, unfortunately, those classes aren't handled by DI container but their names are injected to router and router just instantiates them with hard-coded parameters so it's impossible to reach doctrine annotation reader from inside them without nasty hacks.

My questions are following:
1. Why Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver and Symfony\Component\Routing\Generator\UrlGenerator instances aren't injected by DI container? They could be services - it would follow Symfony principles in my opinion.
2. How to reach DI container from inside them?
3. Is there a better way to achieve what I'm trying to achieve?
Mikz
Junior Member
 
Posts: 1
Joined: Sun May 11, 2014 1:16 pm

Re: Router related classes

by Armand » Thu Nov 27, 2014 1:13 am

I am currently facing the same issue.
I wish to inject an attribute to my class that's extending Symfony's UrlGenerator.
I went creating a CompilerPass class to be able to add a method call on the definition. (The docs clearly state: ... or you need to modify something beyond just the class name, you should use a compiler pass ... )

However the obviouse solution results in:
$container->getDefinition('router.options.generator_base_class');
--> The service definition "router.options.generator_base_class" does not exist.

Is there perhaps a hidden service id for this?
Armand
Junior Member
 
Posts: 2
Joined: Thu Nov 27, 2014 1:06 am

Re: Router related classes

by Armand » Tue Dec 02, 2014 6:20 pm

Well it took a while until I understood howto extend this particular class and inject the Session component in it.

This is how I did it, if anyone would be interested.
http://stackoverflow.com/questions/2713 ... 3#27179103
Armand
Junior Member
 
Posts: 2
Joined: Thu Nov 27, 2014 1:06 am