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

Commite37bff9

Browse files
committed
bug#21602 [DI] Always consider abstract getters as autowiring candidates (nicolas-grekas)
This PR was merged into the 3.3-dev branch.Discussion----------[DI] Always consider abstract getters as autowiring candidates| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes (a missing part of getter autowiring really)| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | -| License | MIT| Doc PR | -When a definition is set to be autowired with no method explicitly configured, we already wire the constructor.We should also autowire abstract getters - with the same reasoning that makes us autowire the constructor: without concrete getters, the class is unusable. This just makes it usable again.Commits-------8f246bd [DI] Always consider abstract getters as autowiring candidates
2 parentsf1f982d +8f246bd commite37bff9

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ private function getMethodsToAutowire(\ReflectionClass $reflectionClass, array $
176176
continue2;
177177
}
178178
}
179+
180+
if ($reflectionMethod->isAbstract() && !$reflectionMethod->getNumberOfParameters()) {
181+
$methodsToAutowire[strtolower($reflectionMethod->name)] =$reflectionMethod;
182+
}
179183
}
180184

181185
if ($notFound =array_diff($autowiredMethods,$found)) {
@@ -501,7 +505,7 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint)
501505
$this->populateAvailableType($argumentId,$argumentDefinition);
502506

503507
try {
504-
$this->processValue($argumentDefinition,true);
508+
$this->processValue($argumentDefinition);
505509
$this->currentId =$currentId;
506510
}catch (RuntimeException$e) {
507511
$classOrInterface =$typeHint->isInterface() ?'interface' :'class';

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useSymfony\Component\DependencyInjection\Compiler\AutowirePass;
1616
useSymfony\Component\DependencyInjection\ContainerBuilder;
1717
useSymfony\Component\DependencyInjection\Reference;
18+
useSymfony\Component\DependencyInjection\Tests\Fixtures\AbstractGetterOverriding;
1819
useSymfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
1920
useSymfony\Component\DependencyInjection\Tests\Fixtures\GetterOverriding;
2021

@@ -519,6 +520,27 @@ public function testExplicitMethodInjection()
519520
);
520521
}
521522

523+
/**
524+
* @requires PHP 7.0
525+
*/
526+
publicfunctiontestAbstractGetterOverriding()
527+
{
528+
$container =newContainerBuilder();
529+
530+
$container
531+
->register('getter_overriding', AbstractGetterOverriding::class)
532+
->setAutowired(true)
533+
;
534+
535+
$pass =newAutowirePass();
536+
$pass->process($container);
537+
538+
$overridenGetters =$container->getDefinition('getter_overriding')->getOverriddenGetters();
539+
$this->assertEquals(array(
540+
'abstractgetfoo' =>newReference('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Foo'),
541+
),$overridenGetters);
542+
}
543+
522544
/**
523545
* @requires PHP 7.1
524546
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
useSymfony\Component\DependencyInjection\Tests\Compiler\Foo;
15+
16+
abstractclass AbstractGetterOverriding
17+
{
18+
abstractpublicfunctionabstractGetFoo():Foo;
19+
abstractpublicfunctionabstractDoFoo($arg =null):Foo;
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp