diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 01330f55907d2..fe744789eaa50 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -9,6 +9,7 @@ CHANGELOG * Add `enum` env var processor * Add `shuffle` env var processor * Add `resolve-env` option to `debug:config` command to display actual values of environment variables in dumped configuration + * Allow #[When] to be extended 6.1 --- diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index 3a3e256e151be..9504c4cee664f 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -120,7 +120,7 @@ public function registerClasses(Definition $prototype, string $namespace, string if (null === $errorMessage && $autoconfigureAttributes && $this->env) { $r = $this->container->getReflectionClass($class); $attribute = null; - foreach ($r->getAttributes(When::class) as $attribute) { + foreach ($r->getAttributes(When::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { if ($this->env === $attribute->newInstance()->env) { $attribute = null; break; diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index 629ca506845c6..7c279d19b241d 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php @@ -101,7 +101,7 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont $r = new \ReflectionFunction($callback); $attribute = null; - foreach ($r->getAttributes(When::class) as $attribute) { + foreach ($r->getAttributes(When::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) { if ($this->env === $attribute->newInstance()->env) { $attribute = null; break; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php index 49545a8dfa2e6..807c8b3e20086 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php @@ -4,7 +4,7 @@ use Symfony\Component\DependencyInjection\Attribute\When; -#[When(env: 'prod')] +#[ProductionOnly] #[When(env: 'dev')] class Foo implements FooInterface, Sub\BarInterface { @@ -16,3 +16,12 @@ public function setFoo(self $foo) { } } + +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION | \Attribute::IS_REPEATABLE)] +class ProductionOnly extends When +{ + public function __construct() + { + parent::__construct('prod'); + } +} 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