From 8da7d03c93669667772d4cd9f1f7cd4cd3f9513b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 10 Jan 2020 17:31:05 +0100 Subject: [PATCH] Use PHP to define the services and routes of the app --- .../framework-bundle/5.1/config/routes.php | 12 ++++ .../framework-bundle/5.1/config/services.php | 59 +++++++++++++++++++ .../framework-bundle/5.1/config/services.yaml | 1 - symfony/framework-bundle/5.1/src/Kernel.php | 18 +++++- symfony/routing/5.1/config/packages | 1 + symfony/routing/5.1/manifest.json | 6 ++ 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 symfony/framework-bundle/5.1/config/routes.php create mode 100644 symfony/framework-bundle/5.1/config/services.php delete mode 120000 symfony/framework-bundle/5.1/config/services.yaml create mode 120000 symfony/routing/5.1/config/packages create mode 100644 symfony/routing/5.1/manifest.json diff --git a/symfony/framework-bundle/5.1/config/routes.php b/symfony/framework-bundle/5.1/config/routes.php new file mode 100644 index 00000000..09deb589 --- /dev/null +++ b/symfony/framework-bundle/5.1/config/routes.php @@ -0,0 +1,12 @@ +add('index', '/') +// ->controller([App\Controller\DefaultController::class, 'index']) +// ; + +}; diff --git a/symfony/framework-bundle/5.1/config/services.php b/symfony/framework-bundle/5.1/config/services.php new file mode 100644 index 00000000..5e359355 --- /dev/null +++ b/symfony/framework-bundle/5.1/config/services.php @@ -0,0 +1,59 @@ +parameters() + // ->set(...) + ; + + $services = $container->services() + ->defaults() + ->autowire() + ->autoconfigure() + ; + + // Makes classes in src/ available to be used as services + $src = dirname(__DIR__).'/src'; + $services + ->load('App\\', $src) + ->exclude([ + $src.'/DependencyInjection', + $src.'/Entity', + $src.'/Migrations', + $src.'/Tests', + $src.'/Kernel.php', + ]) + ; + + // Controllers are imported separately to make sure services can be injected + // as action arguments even if you don't extend any base controller class + $services + ->load('App\\Controller\\', $src.'/Controller') + ->tag('controller.service_arguments') + ; + + // Add more service definitions when explicit configuration is needed. + // Please note that last definitions *replace* previous ones when using $services->set(). + // It is possible to alter a previously declared definition by using $services->get() instead. + $services + // ->set(App\MyService::class) + // ->args([di\ref(App\AnotherService::class)]) + ; + + if ('test' === $kernel->getEnvironment()) { + // When a test case needs access to a service, getting it via + // a public alias with the "test." prefix is recommended. + $services->public() + // ->alias('test.App\MyService', App\MyService::class) + ; + } + +}; diff --git a/symfony/framework-bundle/5.1/config/services.yaml b/symfony/framework-bundle/5.1/config/services.yaml deleted file mode 120000 index be69bb02..00000000 --- a/symfony/framework-bundle/5.1/config/services.yaml +++ /dev/null @@ -1 +0,0 @@ -../../4.2/config/services.yaml \ No newline at end of file diff --git a/symfony/framework-bundle/5.1/src/Kernel.php b/symfony/framework-bundle/5.1/src/Kernel.php index 9f673a45..103e17b6 100644 --- a/symfony/framework-bundle/5.1/src/Kernel.php +++ b/symfony/framework-bundle/5.1/src/Kernel.php @@ -15,14 +15,26 @@ class Kernel extends BaseKernel { $container->import('../config/{packages}/*.yaml'); $container->import('../config/{packages}/'.$this->environment.'/*.yaml'); - $container->import('../config/{services}.yaml'); - $container->import('../config/{services}_'.$this->environment.'.yaml'); + + if (file_exists(\dirname(__DIR__).'/config/services.yaml')) { + $container->import('../config/{services}.yaml'); + $container->import('../config/{services}_'.$this->environment.'.yaml'); + } else { + $path = \dirname(__DIR__).'/config/services.php'; + (require $path)($container->withPath($path), $this); + } } protected function configureRoutes(RoutingConfigurator $routes): void { $routes->import('../config/{routes}/'.$this->environment.'/*.yaml'); $routes->import('../config/{routes}/*.yaml'); - $routes->import('../config/{routes}.yaml'); + + if (file_exists(\dirname(__DIR__).'/config/routes.yaml')) { + $routes->import('../config/{routes}.yaml'); + } else { + $path = \dirname(__DIR__).'/config/routes.php'; + (require $path)($routes->withPath($path), $this); + } } } diff --git a/symfony/routing/5.1/config/packages b/symfony/routing/5.1/config/packages new file mode 120000 index 00000000..d3c89450 --- /dev/null +++ b/symfony/routing/5.1/config/packages @@ -0,0 +1 @@ +../../4.2/config/packages/ \ No newline at end of file diff --git a/symfony/routing/5.1/manifest.json b/symfony/routing/5.1/manifest.json new file mode 100644 index 00000000..c0c66b64 --- /dev/null +++ b/symfony/routing/5.1/manifest.json @@ -0,0 +1,6 @@ +{ + "copy-from-recipe": { + "config/": "%CONFIG_DIR%/" + }, + "aliases": ["router"] +}