|
15 | 15 | use Symfony\Component\Config\Builder\ConfigBuilderGeneratorInterface;
|
16 | 16 | use Symfony\Component\Config\Builder\ConfigBuilderInterface;
|
17 | 17 | use Symfony\Component\Config\FileLocatorInterface;
|
| 18 | +use Symfony\Component\DependencyInjection\Attribute\When; |
18 | 19 | use Symfony\Component\DependencyInjection\Container;
|
19 | 20 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
20 | 21 | use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
@@ -55,12 +56,12 @@ public function load($resource, string $type = null)
|
55 | 56 | $this->container->fileExists($path);
|
56 | 57 |
|
57 | 58 | // the closure forbids access to the private scope in the included file
|
58 |
| - $load = \Closure::bind(function ($path) use ($container, $loader, $resource, $type) { |
| 59 | + $load = \Closure::bind(function ($path, $env) use ($container, $loader, $resource, $type) { |
59 | 60 | return include $path;
|
60 | 61 | }, $this, ProtectedPhpFileLoader::class);
|
61 | 62 |
|
62 | 63 | try {
|
63 |
| - $callback = $load($path); |
| 64 | + $callback = $load($path, $this->env); |
64 | 65 |
|
65 | 66 | if (\is_object($callback) && \is_callable($callback)) {
|
66 | 67 | $this->executeCallback($callback, new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path);
|
@@ -98,8 +99,22 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont
|
98 | 99 |
|
99 | 100 | $arguments = [];
|
100 | 101 | $configBuilders = [];
|
101 |
| - $parameters = (new \ReflectionFunction($callback))->getParameters(); |
102 |
| - foreach ($parameters as $parameter) { |
| 102 | + $r = new \ReflectionFunction($callback); |
| 103 | + |
| 104 | + if (\PHP_VERSION_ID >= 80000) { |
| 105 | + $attribute = null; |
| 106 | + foreach ($r->getAttributes(When::class) as $attribute) { |
| 107 | + if ($this->env === $attribute->newInstance()->env) { |
| 108 | + $attribute = null; |
| 109 | + break; |
| 110 | + } |
| 111 | + } |
| 112 | + if (null !== $attribute) { |
| 113 | + return; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + foreach ($r->getParameters() as $parameter) { |
103 | 118 | $reflectionType = $parameter->getType();
|
104 | 119 | if (!$reflectionType instanceof \ReflectionNamedType) {
|
105 | 120 | throw new \InvalidArgumentException(sprintf('Could not resolve argument "$%s" for "%s". You must typehint it (for example with "%s" or "%s").', $parameter->getName(), $path, ContainerConfigurator::class, ContainerBuilder::class));
|
|
0 commit comments