Skip to content

Commit f6c4b67

Browse files
committed
bug #34515 [DependencyInjection] definitions are valid objects (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] definitions are valid objects | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #34480 | License | MIT | Doc PR | Commits ------- 0acaa5c definitions are valid objects
2 parents 218eb24 + 0acaa5c commit f6c4b67

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
152152
return;
153153
}
154154

155+
if ('object' === $type) {
156+
return;
157+
}
158+
155159
if (is_a($class, $type, true)) {
156160
return;
157161
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1616
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\Reference;
1920
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Bar;
2021
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall;
2122
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgument;
2223
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
2324
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
25+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
2426

2527
/**
2628
* @author Nicolas Grekas <p@tchwork.com>
@@ -390,6 +392,18 @@ public function testProcessSuccessWhenPassingAnIteratorArgumentToIterable()
390392
$this->addToAssertionCount(1);
391393
}
392394

395+
public function testProcessSuccessWhenPassingDefintionForObjectType()
396+
{
397+
$container = new ContainerBuilder();
398+
399+
$container->register('foo_object', FooObject::class)
400+
->addArgument(new Definition(Foo::class));
401+
402+
(new CheckTypeDeclarationsPass(true))->process($container);
403+
404+
$this->addToAssertionCount(1);
405+
}
406+
393407
public function testProcessFactory()
394408
{
395409
$container = new ContainerBuilder();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass;
4+
5+
class FooObject
6+
{
7+
public function __construct(object $foo)
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy