Skip to content

Commit ff3a211

Browse files
[DependencyInjection] Remove deprecations across the component
1 parent 107d0f5 commit ff3a211

35 files changed

+91
-994
lines changed

Argument/ReferenceSetArgumentTrait.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

Attribute/MapDecorated.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Remove `#[MapDecorated]`, use `#[AutowireDecorated]` instead
8+
* Remove `ProxyHelper`, use `Symfony\Component\VarExporter\ProxyHelper` instead
9+
* Remove `ReferenceSetArgumentTrait`
10+
* Remove support of `@required` annotation, use the `Symfony\Contracts\Service\Attribute\Required` attribute instead
11+
* Passing `null` to `ContainerAwareTrait::setContainer()` must be done explicitly
12+
* Remove `PhpDumper` options `inline_factories_parameter` and `inline_class_loader_parameter`, use options `inline_factories` and `inline_class_loader` instead
13+
* Parameter names of `ParameterBag` cannot be numerics
14+
* Remove `ContainerAwareInterface` and `ContainerAwareTrait`, use dependency injection instead
15+
416
6.4
517
---
618

Compiler/AutowirePass.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1616
use Symfony\Component\DependencyInjection\Attribute\AutowireCallable;
1717
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
18-
use Symfony\Component\DependencyInjection\Attribute\MapDecorated;
1918
use Symfony\Component\DependencyInjection\Attribute\Target;
2019
use Symfony\Component\DependencyInjection\ContainerBuilder;
2120
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -98,7 +97,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
9897
return $this->processValue($this->container->getParameterBag()->resolveValue($value->value));
9998
}
10099

101-
if ($value instanceof AutowireDecorated || $value instanceof MapDecorated) {
100+
if ($value instanceof AutowireDecorated) {
102101
$definition = $this->container->getDefinition($this->currentId);
103102

104103
return new Reference($definition->innerServiceId ?? $this->currentId.'.inner', $definition->decorationOnInvalid ?? ContainerInterface::NULL_ON_INVALID_REFERENCE);
@@ -358,12 +357,6 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
358357

359358
continue 2;
360359
}
361-
362-
foreach ($parameter->getAttributes(MapDecorated::class) as $attribute) {
363-
$arguments[$index] = $this->processValue($attribute->newInstance());
364-
365-
continue 2;
366-
}
367360
}
368361

369362
if (!$type) {

Compiler/AutowireRequiredMethodsPass.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
5757
}
5858
break;
5959
}
60-
if (false !== $doc = $r->getDocComment()) {
61-
if (false !== stripos($doc, '@required') && preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc)) {
62-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Relying on the "@required" annotation on method "%s::%s()" is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.', $reflectionMethod->class, $reflectionMethod->name);
63-
64-
if ($this->isWither($reflectionMethod, $doc)) {
65-
$withers[] = [$reflectionMethod->name, [], true];
66-
} else {
67-
$value->addMethodCall($reflectionMethod->name, []);
68-
}
69-
break;
70-
}
71-
if (false === stripos($doc, '@inheritdoc') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+(?:\{@inheritdoc\}|@inheritdoc)(?:\s|\*/$)#i', $doc)) {
72-
break;
73-
}
74-
}
7560
try {
7661
$r = $r->getPrototype();
7762
} catch (\ReflectionException) {

Compiler/AutowireRequiredPropertiesPass.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
4242
if (!($type = $reflectionProperty->getType()) instanceof \ReflectionNamedType) {
4343
continue;
4444
}
45-
$doc = false;
46-
if (!$reflectionProperty->getAttributes(Required::class)
47-
&& ((false === $doc = $reflectionProperty->getDocComment()) || false === stripos($doc, '@required') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc))
48-
) {
45+
if (!$reflectionProperty->getAttributes(Required::class)) {
4946
continue;
5047
}
51-
if ($doc) {
52-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Using the "@required" annotation on property "%s::$%s" is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.', $reflectionProperty->class, $reflectionProperty->name);
53-
}
5448
if (\array_key_exists($name = $reflectionProperty->getName(), $properties)) {
5549
continue;
5650
}

Compiler/ServiceLocatorTagPass.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
6464
throw new InvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set.', $this->currentId));
6565
}
6666

67-
$i = 0;
68-
69-
foreach ($services as $k => $v) {
70-
if ($v instanceof ServiceClosureArgument) {
71-
continue;
72-
}
73-
74-
if ($i === $k) {
75-
if ($v instanceof Reference) {
76-
unset($services[$k]);
77-
$k = (string) $v;
78-
}
79-
++$i;
80-
} elseif (\is_int($k)) {
81-
$i = null;
82-
}
83-
84-
$services[$k] = new ServiceClosureArgument($v);
85-
}
86-
ksort($services);
87-
88-
$value->setArgument(0, $services);
67+
$value->setArgument(0, self::map($services));
8968

9069
$id = '.service_locator.'.ContainerBuilder::hash($value);
9170

@@ -104,12 +83,8 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
10483

10584
public static function register(ContainerBuilder $container, array $map, string $callerId = null): Reference
10685
{
107-
foreach ($map as $k => $v) {
108-
$map[$k] = new ServiceClosureArgument($v);
109-
}
110-
11186
$locator = (new Definition(ServiceLocator::class))
112-
->addArgument($map)
87+
->addArgument(self::map($map))
11388
->addTag('container.service_locator');
11489

11590
if (null !== $callerId && $container->hasDefinition($callerId)) {
@@ -134,4 +109,30 @@ public static function register(ContainerBuilder $container, array $map, string
134109

135110
return new Reference($id);
136111
}
112+
113+
public static function map(array $services): array
114+
{
115+
$i = 0;
116+
117+
foreach ($services as $k => $v) {
118+
if ($v instanceof ServiceClosureArgument) {
119+
continue;
120+
}
121+
122+
if ($i === $k) {
123+
if ($v instanceof Reference) {
124+
unset($services[$k]);
125+
$k = (string) $v;
126+
}
127+
++$i;
128+
} elseif (\is_int($k)) {
129+
$i = null;
130+
}
131+
132+
$services[$k] = new ServiceClosureArgument($v);
133+
}
134+
ksort($services);
135+
136+
return $services;
137+
}
137138
}

ContainerAwareInterface.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

ContainerAwareTrait.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

Dumper/PhpDumper.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public function dump(array $options = []): string|array
145145
'debug' => true,
146146
'hot_path_tag' => 'container.hot_path',
147147
'preload_tags' => ['container.preload', 'container.no_preload'],
148-
'inline_factories_parameter' => 'container.dumper.inline_factories', // @deprecated since Symfony 6.3
149-
'inline_class_loader_parameter' => 'container.dumper.inline_class_loader', // @deprecated since Symfony 6.3
150148
'inline_factories' => null,
151149
'inline_class_loader' => null,
152150
'preload_classes' => [],
@@ -163,22 +161,11 @@ public function dump(array $options = []): string|array
163161
$this->inlineFactories = false;
164162
if (isset($options['inline_factories'])) {
165163
$this->inlineFactories = $this->asFiles && $options['inline_factories'];
166-
} elseif (!$options['inline_factories_parameter']) {
167-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Option "inline_factories_parameter" passed to "%s()" is deprecated, use option "inline_factories" instead.', __METHOD__);
168-
} elseif ($this->container->hasParameter($options['inline_factories_parameter'])) {
169-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Option "inline_factories_parameter" passed to "%s()" is deprecated, use option "inline_factories" instead.', __METHOD__);
170-
$this->inlineFactories = $this->asFiles && $this->container->getParameter($options['inline_factories_parameter']);
171164
}
172165

173166
$this->inlineRequires = $options['debug'];
174167
if (isset($options['inline_class_loader'])) {
175168
$this->inlineRequires = $options['inline_class_loader'];
176-
} elseif (!$options['inline_class_loader_parameter']) {
177-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Option "inline_class_loader_parameter" passed to "%s()" is deprecated, use option "inline_class_loader" instead.', __METHOD__);
178-
$this->inlineRequires = false;
179-
} elseif ($this->container->hasParameter($options['inline_class_loader_parameter'])) {
180-
trigger_deprecation('symfony/dependency-injection', '6.3', 'Option "inline_class_loader_parameter" passed to "%s()" is deprecated, use option "inline_class_loader" instead.', __METHOD__);
181-
$this->inlineRequires = $this->container->getParameter($options['inline_class_loader_parameter']);
182169
}
183170

184171
$this->serviceLocatorTag = $options['service_locator_tag'];

0 commit comments

Comments
 (0)