Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deprecated-packages/symfonymodularrouting
[DEPRECATED] Decouple your Symfony routing to independent, standalone services.
https://github.com/deprecated-packages/symfonymodularrouting
modular php php71 routing symfony symfony32 symplify
Last synced: 2 months ago
JSON representation
[DEPRECATED] Decouple your Symfony routing to independent, standalone services.
- Host: GitHub
- URL: https://github.com/deprecated-packages/symfonymodularrouting
- Owner: deprecated-packages
- License: mit
- Created: 2016-01-20T13:28:13.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-12T21:14:39.000Z (over 7 years ago)
- Last Synced: 2024-10-12T12:22:33.067Z (2 months ago)
- Topics: modular, php, php71, routing, symfony, symfony32, symplify
- Language: PHP
- Homepage: https://www.tomasvotruba.cz/blog/2016/02/25/modular-routing-in-symfony/
- Size: 71.3 KB
- Stars: 17
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Modular Routing
[![Build Status](https://img.shields.io/travis/Symplify/ModularRouting/master.svg?style=flat-square)](https://travis-ci.org/Symplify/ModularRouting)
[![Downloads](https://img.shields.io/packagist/dt/symplify/modular-routing.svg?style=flat-square)](https://packagist.org/packages/symplify/modular-routing)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](http://www.tomasvotruba.cz/blog/2016/02/25/modular-routing-in-symfony).
**Thanks to this router, you can add them easily as via service loader**.
## Install
```bash
composer require symplify/modular-routing
```Add bundle to `AppKernel.php`:
```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
1. Implement [`RouteCollectionProviderInterface`](src/Contract/Routing/RouteCollectionProviderInterface.php)
```php
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;
}
}
```2. Register service
```yml
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`](src/Routing/AbstractRouteCollectionProvider.php)
with helper methods.```php
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](https://github.com/Symplify/Symplify/issues) or [pull-request](https://github.com/Symplify/Symplify/pulls) to main repository.