prepend new route to routelist

bauer01
Member | 31
+
0
-

I'd like to generate some routes in my compiler extension automatically. They should be inserted before all defined routes in router service, but there is a problem with RouteList class because it implements ArrayAccess which is not compatible with array_unshift. Any idea how to solve it? Maybe add new function prepend() to Nette\Utils\ArrayList?

MyCompilerExtension.php

public function beforeCompile()
{
    $builder = $this->getContainerBuilder();
    $builder->getDefinition("router")->addSetup('$service[] = MyCustomRouterFactory::create');
}
jiri.pudil
Member | 836
+
+1
-

You can take a look at how Kdyby solves this. It's not much elegant, but it works.

Comments

bauer01:

nice, that's enough, thx

4 years ago