PHP code example of symplify / modular-routing

1. Go to this page and download the library: Download symplify/modular-routing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symplify / modular-routing example snippets


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(),
            // ...
        ];
    }
}

    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;
        }
    }
    

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');
    }
}