diff --git a/src/Core/Router/RouteLoader.php b/src/Core/Router/RouteLoader.php index a74a558781..2bfb247f63 100644 --- a/src/Core/Router/RouteLoader.php +++ b/src/Core/Router/RouteLoader.php @@ -1,6 +1,7 @@ . + // }}} /** @@ -46,12 +48,9 @@ class RouteLoader extends Loader * Must conform to symfony's interface, but the $resource is unused * and $type must not be null * - * @param mixed $resource - * @param null|string $type - * - * @return RouteCollection + * @param mixed $resource */ - public function load($resource, string $type = null): RouteCollection + public function load($resource, ?string $type = null): RouteCollection { $this->rc = new RouteCollection(); @@ -70,7 +69,7 @@ class RouteLoader extends Loader * * @param string $id Route unique id, used to generate urls, for instance * @param string $uri_path Path, possibly with {param}s - * @param mixed $target Some kind of callable, typically [object, method] + * @param mixed $target Some kind of callable, typically class with `__invoke` or [object, method] * @param null|array $param_reqs Array of {param} => regex * @param null|array $options Possible keys are ['condition', 'defaults', 'format', * 'fragment', 'http-methods', 'locale', 'methods', 'schemes'] @@ -80,7 +79,7 @@ class RouteLoader extends Loader { $this->rc->add($id, new Route( - // path -- URI path + // path -- URI path $uri_path, // defaults = [] -- param default values, // and special configuration options @@ -118,12 +117,9 @@ class RouteLoader extends Loader * Passed the arguments from the `RoutingConfigurator::import` call from * `config/routes.php` * - * @param mixed $resource Unused - * @param null|string $type - * - * @return bool + * @param mixed $resource */ - public function supports($resource, string $type = null) + public function supports($resource, ?string $type = null): bool { return 'GNUsocial' === $type; } diff --git a/src/Kernel.php b/src/Kernel.php index cda1ca0f97..635c965e8a 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -31,14 +31,13 @@ namespace App; use App\DependencyInjection\Compiler\SchemaDefPass; - use const PHP_VERSION_ID; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\Routing\RouteCollectionBuilder; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class Kernel extends BaseKernel { @@ -103,13 +102,17 @@ class Kernel extends BaseKernel $loader->load($confDir . '/{services}_' . $this->environment . self::CONFIG_EXTS, 'glob'); } - protected function configureRoutes(RouteCollectionBuilder $routes): void + protected function configureRoutes(RoutingConfigurator $routes): void { - $confDir = $this->getProjectDir() . '/config'; + $config = \dirname(__DIR__) . '/config'; + $routes->import($config . '/{routes}/' . $this->environment . '/*.yaml'); + $routes->import($config . '/{routes}/*.yaml'); - $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'); + if (is_file($config . '/routes.yaml')) { + $routes->import($config . '/{routes}.yaml'); + } elseif (is_file($path = $config . '/routes.php')) { + (require $path)($routes->withPath($path), $this); + } } protected function build(ContainerBuilder $container): void