Skip to content

Commit c3674b4

Browse files
committed
bug symfony#44879 [DependencyInjection] Ignore argument type check in CheckTypeDeclarationsPass if it's a Definition with a factory (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Ignore argument type check in CheckTypeDeclarationsPass if it's a Definition with a factory | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | symfony#35599, symfony#44515 | License | MIT | Doc PR | - When a definition uses a factory, we don't know what it returns. Commits ------- b9095e6 [DependencyInjection] Ignore argument type check in CheckTypeDeclarationsPass if it's a Definition with a factory
2 parents ddfaf70 + b9095e6 commit c3674b4

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
210210
$class = null;
211211

212212
if ($value instanceof Definition) {
213+
if ($value->getFactory()) {
214+
return;
215+
}
216+
213217
$class = $value->getClass();
214218

215219
if ($class && isset(self::BUILTIN_TYPES[strtolower($class)])) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,20 @@ public function testCallableClass()
999999

10001000
$this->addToAssertionCount(1);
10011001
}
1002+
1003+
public function testIgnoreDefinitionFactoryArgument()
1004+
{
1005+
$container = new ContainerBuilder();
1006+
$container->register('bar', Bar::class)
1007+
->setArguments([
1008+
(new Definition(Foo::class))
1009+
->setFactory([Foo::class, 'createStdClass']),
1010+
]);
1011+
1012+
(new CheckTypeDeclarationsPass())->process($container);
1013+
1014+
$this->addToAssertionCount(1);
1015+
}
10021016
}
10031017

10041018
class CallableClass

src/Symfony/Component/DependencyInjection/Tests/Fixtures/CheckTypeDeclarationsPass/Foo.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public static function createArray(): array
2323
{
2424
return [];
2525
}
26+
27+
public static function createStdClass(): \stdClass
28+
{
29+
return new \stdClass();
30+
}
2631
}

0 commit comments

Comments
 (0)