From 8f92c8568969373d3a08edd9baa4bb64e0a358e5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 Jan 2020 14:02:49 +0100 Subject: [PATCH] [DI][Routing] add wither to configure the path of PHP-DSL configurators --- .../FrameworkBundle/Kernel/MicroKernelTrait.php | 3 +-- .../flex-style/src/FlexStyleMicroKernel.php | 1 + .../Bundle/FrameworkBundle/composer.json | 2 +- .../Configurator/ContainerConfigurator.php | 17 +++++++++++++---- .../Configurator/ServicesConfigurator.php | 9 +++------ .../Loader/Configurator/RoutingConfigurator.php | 11 +++++++++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php index 4125a9a0d9766..0d899f9e6957b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php @@ -124,7 +124,6 @@ public function registerContainerConfiguration(LoaderInterface $loader) } // the user has opted into using the ContainerConfigurator - $defaultDefinition = (new Definition())->setAutowired(true)->setAutoconfigured(true); /* @var ContainerPhpFileLoader $kernelLoader */ $kernelLoader = $loader->getResolver()->resolve($file); $kernelLoader->setCurrentDir(\dirname($file)); @@ -136,7 +135,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) }; try { - $this->configureContainer(new ContainerConfigurator($container, $kernelLoader, $instanceof, $file, $file, $defaultDefinition), $loader); + $this->configureContainer(new ContainerConfigurator($container, $kernelLoader, $instanceof, $file, $file), $loader); } finally { $instanceof = []; $kernelLoader->registerAliasesForSinglyImplementedInterfaces(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php index e4e0a2777404f..a4843bf988f8e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/flex-style/src/FlexStyleMicroKernel.php @@ -79,6 +79,7 @@ protected function configureContainer(ContainerConfigurator $c) $c->services() ->set('logger', NullLogger::class) ->set('stdClass', 'stdClass') + ->autowire() ->factory([$this, 'createHalloween']) ->arg('$halloween', '%halloween%'); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 896d149b10097..493bc6e9632ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -27,7 +27,7 @@ "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", - "symfony/routing": "^5.0" + "symfony/routing": "^5.1" }, "require-dev": { "doctrine/annotations": "~1.7", diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php index 61fd4ee38a329..f511f82f2a1ae 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php @@ -34,16 +34,14 @@ class ContainerConfigurator extends AbstractConfigurator private $path; private $file; private $anonymousCount = 0; - private $defaultDefinition; - public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path, string $file, Definition $defaultDefinition = null) + public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path, string $file) { $this->container = $container; $this->loader = $loader; $this->instanceof = &$instanceof; $this->path = $path; $this->file = $file; - $this->defaultDefinition = $defaultDefinition; } final public function extension(string $namespace, array $config) @@ -69,7 +67,18 @@ final public function parameters(): ParametersConfigurator final public function services(): ServicesConfigurator { - return new ServicesConfigurator($this->container, $this->loader, $this->instanceof, $this->path, $this->anonymousCount, $this->defaultDefinition); + return new ServicesConfigurator($this->container, $this->loader, $this->instanceof, $this->path, $this->anonymousCount); + } + + /** + * @return static + */ + final public function withPath(string $path): self + { + $clone = clone $this; + $clone->path = $clone->file = $path; + + return $clone; } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php index 358303f660b80..f0fdde81c33a4 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ServicesConfigurator.php @@ -32,19 +32,16 @@ class ServicesConfigurator extends AbstractConfigurator private $path; private $anonymousHash; private $anonymousCount; - private $defaultDefinition; - public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path = null, int &$anonymousCount = 0, Definition $defaultDefinition = null) + public function __construct(ContainerBuilder $container, PhpFileLoader $loader, array &$instanceof, string $path = null, int &$anonymousCount = 0) { - $defaultDefinition = $defaultDefinition ?? new Definition(); - $this->defaults = clone $defaultDefinition; + $this->defaults = new Definition(); $this->container = $container; $this->loader = $loader; $this->instanceof = &$instanceof; $this->path = $path; $this->anonymousHash = ContainerBuilder::hash($path ?: mt_rand()); $this->anonymousCount = &$anonymousCount; - $this->defaultDefinition = $defaultDefinition; $instanceof = []; } @@ -53,7 +50,7 @@ public function __construct(ContainerBuilder $container, PhpFileLoader $loader, */ final public function defaults(): DefaultsConfigurator { - return new DefaultsConfigurator($this, $this->defaults = clone $this->defaultDefinition, $this->path); + return new DefaultsConfigurator($this, $this->defaults = new Definition(), $this->path); } /** diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php index 8ed06f307c646..e5086e2441b85 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php @@ -57,4 +57,15 @@ final public function collection(string $name = ''): CollectionConfigurator { return new CollectionConfigurator($this->collection, $name); } + + /** + * @return static + */ + final public function withPath(string $path): self + { + $clone = clone $this; + $clone->path = $clone->file = $path; + + return $clone; + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy