Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit95fd81b

Browse files
[DI] deprecate TypedReference::canBeAutoregistered() and getRequiringClass()
1 parent9131bd1 commit95fd81b

File tree

12 files changed

+56
-32
lines changed

12 files changed

+56
-32
lines changed

‎UPGRADE-4.1.md‎

Lines 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‎

Lines 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‎

Lines 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‎

Lines 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 =newTypedReference($type,$type, !$parameter->isOptional() ?$class :''))) {
211+
if (!$value =$this->getAutowiredReference($ref =newTypedReference($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‎

Lines 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] =newReference($type);
8685
}
8786

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

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

Lines 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-
newTypedReference(A::class, A::class, MultipleArguments::class),
386+
newTypedReference(A::class, A::class),
387387
newReference('foo'),
388-
newTypedReference(Dunglas::class, Dunglas::class, MultipleArguments::class),
388+
newTypedReference(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-
newTypedReference(A::class, A::class, MultipleArgumentsOptionalScalar::class),
441+
newTypedReference(A::class, A::class),
442442
// use the default value
443443
'default_val',
444444
newTypedReference(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-
newTypedReference(A::class, A::class, MultipleArgumentsOptionalScalarLast::class),
466-
newTypedReference(Lille::class, Lille::class, MultipleArgumentsOptionalScalarLast::class),
465+
newTypedReference(A::class, A::class),
466+
newTypedReference(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(newTypedReference(Foo::class, Foo::class, SetterInjection::class)),
522+
array(newTypedReference(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(newTypedReference(A::class, A::class, SetterInjection::class)),
552+
array(newTypedReference(A::class, A::class)),
553553
$methodCalls[0][1]
554554
);
555555
}
@@ -647,7 +647,7 @@ public function testEmptyStringIsKept()
647647
(newResolveClassPass())->process($container);
648648
(newAutowirePass())->process($container);
649649

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

653653
publicfunctiontestWithFactory()
@@ -662,7 +662,7 @@ public function testWithFactory()
662662
(newResolveClassPass())->process($container);
663663
(newAutowirePass())->process($container);
664664

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

668668
/**

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

Lines 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 =>newServiceClosureArgument(newTypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
83-
CustomDefinition::class =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class,TestServiceSubscriber::class,ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
84-
'bar' =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class, TestServiceSubscriber::class)),
85-
'baz' =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class,TestServiceSubscriber::class,ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
82+
TestServiceSubscriber::class =>newServiceClosureArgument(newTypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)),
83+
CustomDefinition::class =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
84+
'bar' =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class)),
85+
'baz' =>newServiceClosureArgument(newTypedReference(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 =>newServiceClosureArgument(newTypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class, TestServiceSubscriber::class)),
113-
CustomDefinition::class =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class,TestServiceSubscriber::class,ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
114-
'bar' =>newServiceClosureArgument(newTypedReference('bar', CustomDefinition::class, TestServiceSubscriber::class)),
115-
'baz' =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class,TestServiceSubscriber::class,ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
112+
TestServiceSubscriber::class =>newServiceClosureArgument(newTypedReference(TestServiceSubscriber::class, TestServiceSubscriber::class)),
113+
CustomDefinition::class =>newServiceClosureArgument(newTypedReference(CustomDefinition::class, CustomDefinition::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)),
114+
'bar' =>newServiceClosureArgument(newTypedReference('bar', CustomDefinition::class)),
115+
'baz' =>newServiceClosureArgument(newTypedReference(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‎

Lines 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‎

Lines changed: 18 additions & 4 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-
publicfunction__construct(string$id,string$type,string$requiringClass ='',int$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
29+
publicfunction__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 $requiringClass argument of "%s" 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
publicfunctiongetType()
3842
{
3943
return$this->type;
4044
}
4145

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

56+
/**
57+
* @deprecated since Symfony 4.1
58+
*/
4759
publicfunctioncanBeAutoregistered()
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function process(ContainerBuilder $container)
164164
thrownewInvalidArgumentException($message);
165165
}
166166

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp