Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fdbddaa

Browse filesBrowse files
[DI] deprecate TypedReference::canBeAutoregistered()
1 parent 9131bd1 commit fdbddaa
Copy full SHA for fdbddaa

12 files changed

+55
-31
lines changed

‎UPGRADE-4.1.md

Copy file name to clipboardExpand all lines: UPGRADE-4.1.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Console
1212

1313
* Deprecated the `setCrossingChar()` method in favor of the `setDefaultCrossingChar()` method in `TableStyle`.
1414

15+
DependencyInjection
16+
-------------------
17+
18+
* Deprecated the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods.
19+
1520
EventDispatcher
1621
---------------
1722

‎UPGRADE-5.0.md

Copy file name to clipboardExpand all lines: UPGRADE-5.0.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Console
1111

1212
* Removed the `setCrossingChar()` method in favor of the `setDefaultCrossingChar()` method in `TableStyle`.
1313

14+
DependencyInjection
15+
-------------------
16+
17+
* Removed the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods.
18+
1419
EventDispatcher
1520
---------------
1621

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* added support for variadics in named arguments
88
* added PSR-11 `ContainerBagInterface` and its `ContainerBag` implementation to access parameters as-a-service
99
* added support for service's decorators autowiring
10+
* deprecated the `TypedReference::canBeAutoregistered()` and `TypedReference::getRequiringClass()` methods
1011

1112
4.0.0
1213
-----

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
208208
}
209209

210210
$getValue = function () use ($type, $parameter, $class, $method) {
211-
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''))) {
211+
if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type))) {
212212
$failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
213213

214214
if ($parameter->isDefaultValueAvailable()) {

‎src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ protected function processValue($value, $isRoot = false)
6565
$class = $r->name;
6666

6767
$subscriberMap = array();
68-
$declaringClass = (new \ReflectionMethod($class, 'getSubscribedServices'))->class;
6968

7069
foreach ($class::getSubscribedServices() as $key => $type) {
7170
if (!is_string($type) || !preg_match('/^\??[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $type)) {
@@ -85,7 +84,7 @@ protected function processValue($value, $isRoot = false)
8584
$serviceMap[$key] = new Reference($type);
8685
}
8786

88-
$subscriberMap[$key] = new TypedReference((string) $serviceMap[$key], $type, $declaringClass, $optionalBehavior ?: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
87+
$subscriberMap[$key] = new TypedReference((string) $serviceMap[$key], $type, $optionalBehavior ?: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
8988
unset($serviceMap[$key]);
9089
}
9190

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ public function testSomeSpecificArgumentsAreSet()
383383
$definition = $container->getDefinition('multiple');
384384
$this->assertEquals(
385385
array(
386-
new TypedReference(A::class, A::class, MultipleArguments::class),
386+
new TypedReference(A::class, A::class),
387387
new Reference('foo'),
388-
new TypedReference(Dunglas::class, Dunglas::class, MultipleArguments::class),
388+
new TypedReference(Dunglas::class, Dunglas::class),
389389
),
390390
$definition->getArguments()
391391
);
@@ -438,7 +438,7 @@ public function testOptionalScalarArgsDontMessUpOrder()
438438
$definition = $container->getDefinition('with_optional_scalar');
439439
$this->assertEquals(
440440
array(
441-
new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class),
441+
new TypedReference(A::class, A::class),
442442
// use the default value
443443
'default_val',
444444
new TypedReference(Lille::class, Lille::class),
@@ -462,8 +462,8 @@ public function testOptionalScalarArgsNotPassedIfLast()
462462
$definition = $container->getDefinition('with_optional_scalar_last');
463463
$this->assertEquals(
464464
array(
465-
new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalarLast::class),
466-
new TypedReference(Lille::class, Lille::class, MultipleArgumentsOptionalScalarLast::class),
465+
new TypedReference(A::class, A::class),
466+
new TypedReference(Lille::class, Lille::class),
467467
),
468468
$definition->getArguments()
469469
);
@@ -519,7 +519,7 @@ public function testSetterInjection()
519519
);
520520
// test setFoo args
521521
$this->assertEquals(
522-
array(new TypedReference(Foo::class, Foo::class, SetterInjection::class)),
522+
array(new TypedReference(Foo::class, Foo::class)),
523523
$methodCalls[1][1]
524524
);
525525
}
@@ -549,7 +549,7 @@ public function testExplicitMethodInjection()
549549
array_column($methodCalls, 0)
550550
);
551551
$this->assertEquals(
552-
array(new TypedReference(A::class, A::class, SetterInjection::class)),
552+
array(new TypedReference(A::class, A::class)),
553553
$methodCalls[0][1]
554554
);
555555
}
@@ -647,7 +647,7 @@ public function testEmptyStringIsKept()
647647
(new ResolveClassPass())->process($container);
648648
(new AutowirePass())->process($container);
649649

650-
$this->assertEquals(array(new TypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class), '', new TypedReference(Lille::class, Lille::class)), $container->getDefinition('foo')->getArguments());
650+
$this->assertEquals(array(new TypedReference(A::class, A::class), '', new TypedReference(Lille::class, Lille::class)), $container->getDefinition('foo')->getArguments());
651651
}
652652

653653
public function testWithFactory()
@@ -662,7 +662,7 @@ public function testWithFactory()
662662
(new ResolveClassPass())->process($container);
663663
(new AutowirePass())->process($container);
664664

665-
$this->assertEquals(array(new TypedReference(Foo::class, Foo::class, A::class)), $definition->getArguments());
665+
$this->assertEquals(array(new TypedReference(Foo::class, Foo::class)), $definition->getArguments());
666666
}
667667

668668
/**

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public function testNoAttributes()
7979
$this->assertSame(ServiceLocator::class, $locator->getClass());
8080

8181
$expected = array(
82-
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
83-
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
84-
'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class)),
85-
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
82+
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)),
83+
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
84+
'bar' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class)),
85+
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
8686
);
8787

8888
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
@@ -109,10 +109,10 @@ public function testWithAttributes()
109109
$this->assertSame(ServiceLocator::class, $locator->getClass());
110110

111111
$expected = array(
112-
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
113-
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
114-
'bar' => new ServiceClosureArgument(new TypedReference('bar', CustomDefinition::class, TestServiceSubscriber::class)),
115-
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
112+
TestServiceSubscriber::class => new ServiceClosureArgument(new TypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)),
113+
CustomDefinition::class => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
114+
'bar' => new ServiceClosureArgument(new TypedReference('bar', CustomDefinition::class)),
115+
'baz' => new ServiceClosureArgument(new TypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
116116
);
117117

118118
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function getRemovedIds()
5757
'Psr\\Container\\ContainerInterface' => true,
5858
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
5959
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
60-
'service_locator.KT3jhJ7' => true,
61-
'service_locator.KT3jhJ7.foo_service' => true,
60+
'service_locator.ljJrY4L' => true,
61+
'service_locator.ljJrY4L.foo_service' => true,
6262
);
6363
}
6464

‎src/Symfony/Component/DependencyInjection/TypedReference.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/TypedReference.php
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,42 @@ class TypedReference extends Reference
2424
/**
2525
* @param string $id The service identifier
2626
* @param string $type The PHP type of the identified service
27-
* @param string $requiringClass The class of the service that requires the referenced type
2827
* @param int $invalidBehavior The behavior when the service does not exist
2928
*/
30-
public function __construct(string $id, string $type, string $requiringClass = '', int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
29+
public function __construct(string $id, string $type, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
3130
{
31+
if (\is_string($invalidBehavior) || 3 < \func_num_args()) {
32+
@trigger_error(sprintf('The 3rd argument of "%s" ($requiringClass) is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED);
33+
34+
$this->requiringClass = $invalidBehavior;
35+
$invalidBehavior = 3 < \func_num_args() ? \func_get_arg(3) : ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
36+
}
3237
parent::__construct($id, $invalidBehavior);
3338
$this->type = $type;
34-
$this->requiringClass = $requiringClass;
3539
}
3640

3741
public function getType()
3842
{
3943
return $this->type;
4044
}
4145

46+
/**
47+
* @deprecated since Symfony 4.1
48+
*/
4249
public function getRequiringClass()
4350
{
51+
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED);
52+
4453
return $this->requiringClass;
4554
}
4655

56+
/**
57+
* @deprecated since Symfony 4.1
58+
*/
4759
public function canBeAutoregistered()
4860
{
61+
@trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED);
62+
4963
return $this->requiringClass && (false !== $i = strpos($this->type, '\\')) && 0 === strncasecmp($this->type, $this->requiringClass, 1 + $i);
5064
}
5165
}

‎src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function process(ContainerBuilder $container)
164164
throw new InvalidArgumentException($message);
165165
}
166166

167-
$args[$p->name] = $type ? new TypedReference($target, $type, $r->class, $invalidBehavior) : new Reference($target, $invalidBehavior);
167+
$args[$p->name] = $type ? new TypedReference($target, $type, $invalidBehavior) : new Reference($target, $invalidBehavior);
168168
}
169169
// register the maps as a per-method service-locators
170170
if ($args) {

‎src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function testAllActions()
148148
$this->assertSame(ServiceLocator::class, $locator->getClass());
149149
$this->assertFalse($locator->isPublic());
150150

151-
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
151+
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
152152
$this->assertEquals($expected, $locator->getArgument(0));
153153
}
154154

@@ -168,7 +168,7 @@ public function testExplicitArgument()
168168
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
169169
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
170170

171-
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class)));
171+
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class)));
172172
$this->assertEquals($expected, $locator->getArgument(0));
173173
}
174174

@@ -187,7 +187,7 @@ public function testOptionalArgument()
187187
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
188188
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
189189

190-
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, RegisterTestController::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
190+
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
191191
$this->assertEquals($expected, $locator->getArgument(0));
192192
}
193193

‎src/Symfony/Component/HttpKernel/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/config": "~3.4|~4.0",
2828
"symfony/console": "~3.4|~4.0",
2929
"symfony/css-selector": "~3.4|~4.0",
30-
"symfony/dependency-injection": "^3.4.5|^4.0.5",
30+
"symfony/dependency-injection": "^4.1",
3131
"symfony/dom-crawler": "~3.4|~4.0",
3232
"symfony/expression-language": "~3.4|~4.0",
3333
"symfony/finder": "~3.4|~4.0",
@@ -44,7 +44,7 @@
4444
},
4545
"conflict": {
4646
"symfony/config": "<3.4",
47-
"symfony/dependency-injection": "<3.4.5|<4.0.5,>=4",
47+
"symfony/dependency-injection": "<4.1",
4848
"symfony/var-dumper": "<3.4",
4949
"twig/twig": "<1.34|<2.4,>=2"
5050
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.