Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoloading routing from Symfony 2 bundles

Tags:

php

symfony

Symfony 2 bundles have a nice feature for autoloading/extending the application configuration files, such as services.yml. However, this is not true for routing, since i have to manually edit the routing.yml of my application in order to load the routing data from my Bundle (the Controller or the routing.yml itself).

Is it possible to load such routing configuration this seamlessly?

---- EDIT

I ended up doing this, but it's ugly as hell:

<?php

use Symfony\Component\Routing\RouteCollection;

$collection = new RouteCollection();

foreach (glob(__DIR__.'/../../src/Vendor/MySystem/Plugins/*Bundle/Controller/', GLOB_ONLYDIR) as $controller) {
    $controller = str_replace(__DIR__.'/../../src/Vendor/MySystem/Plugins/', '', $controller);
    $collection->addCollection($loader->import("@$controller"));
}

return $collection;
like image 465
Klaus S. Avatar asked Jan 29 '13 16:01

Klaus S.


1 Answers

i think you should look after the "routing.loader" dependency injection tag It let you define a class to define routes with your logic

http://symfony.com/doc/current/reference/dic_tags.html#routing-loader

I think You could also define an dependencyInjection extension in your bundle. In your load method, you can alter the container definitions and so your routes..

like image 175
Julien Rollin Avatar answered Oct 28 '22 22:10

Julien Rollin