<?php
namespace AppBundle\Service\Routing;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Bundle\FrameworkBundle\Routing\RouteLoaderInterface;
class AppRouteLoader implements RouteLoaderInterface
{
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
private string $projectDir;
private string $environment;
public function __construct(string $projectDir, string $environment)
{
$this->projectDir = $projectDir;
$this->environment = $environment;
}
/**
* @internal
*/
public function loadRoutes(LoaderInterface $loader): RouteCollection
{
$routes = new RouteCollectionBuilder($loader);
$this->configureRoutes($routes);
return $routes->build();
}
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->projectDir.'/app/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
}