symplify / modular-routing
This package is abandoned and no longer maintained.
The author suggests using the symplify/framework-bundle package instead.
There is no license information available for the latest version (v2.0.0-RC3) of this package.
Load your Symfony routes with a simple service.
v2.0.0-RC3
2017-04-28 19:16 UTC
Requires
- php: ^7.1
- doctrine/doctrine-bundle: ^1.6
- symfony-cmf/routing-bundle: ^2.0
- symfony/asset: ^3.3
- symfony/config: ^3.3
- symfony/dependency-injection: ^3.3
- symfony/framework-bundle: ^3.3
- symfony/http-kernel: ^3.3
- symfony/routing: ^3.3
- symfony/templating: ^3.3
- symfony/twig-bundle: ^3.3
- symfony/validator: ^3.3
- symfony/yaml: ^3.3
Requires (Dev)
- doctrine/annotations: ^1.4
- nette/finder: ^2.4
- nette/utils: ^2.4
- phpunit/phpunit: ^6.0
- symfony/form: ^3.3
- twig/twig: ^2.2
- dev-master
- v2.0.0-RC3
- v2.0.0-RC2
- v2.0.0-RC1
- v1.4.10
- v1.4.9
- v1.4.4
- v1.4.1
- v1.4.0
- v1.3.3
- v1.3.0
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.0
This package is auto-updated.
Last update: 2022-03-08 10:48:44 UTC
README
To add routes you usually need to add few lines to app/config/routing.yml
. If you have over dozens of modules, it would be easy to get lost in it. To see all options on how to do that including this package, read this short article.
Thanks to this router, you can add them easily as via service loader.
Install
composer require symplify/modular-routing
Add bundle to AppKernel.php
:
final class AppKernel extends Kernel { public function registerBundles(): array { $bundles = [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(), new Symplify\ModularRouting\SymplifyModularRoutingBundle(), // ... ]; } }
Usage
-
Implement
RouteCollectionProviderInterface
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symplify\ModularRouting\Contract\Routing\RouteCollectionProviderInterface; final class SomeRouteCollectionProvider implements RouteCollectionProviderInterface { public function getRouteCollection() : RouteCollection { $routeCollection = new RouteCollection(); $routeCollection->add('my_route', new Route('/hello')); return $routeCollection; } }
-
Register service
services: some_module.route_provider: class: SomeModule\Routing\SomeRouteCollectionProvider autowire: true # or better use Symplify\DefaultAutowire package
That's all!
Loading YML/XML files
In case you want to load these files, just use AbstractRouteCollectionProvider
with helper methods.
use Symfony\Component\Routing\RouteCollection; use Symplify\ModularRouting\Routing\AbstractRouteCollectionProvider; final class FilesRouteCollectionProvider extends AbstractRouteCollectionProvider { public function getRouteCollection(): RouteCollection { return $this->loadRouteCollectionFromFiles([ __DIR__ . '/routes.xml', __DIR__ . '/routes.yml', ]); // on in case you have only 1 file // return $this->loadRouteCollectionFromFile(__DIR__ . '/routes.yml'); } }
Contributing
Send issue or pull-request to main repository.