SkillAgentSearch skills...

SymfonyModularRouting

[DEPRECATED] Decouple your Symfony routing to independent, standalone services.

Install / Use

/learn @deprecated-packages/SymfonyModularRouting
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Modular Routing

Build Status Downloads

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

  1. 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;
        }
    }
    
  2. 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.

View on GitHub
GitHub Stars17
CategoryDevelopment
Updated2y ago
Forks2

Languages

PHP

Security Score

80/100

Audited on Aug 11, 2023

No findings