Skip to content

Commit 2fad429

Browse files
committed
Merge branch '3.0'
* 3.0: #17676 - making the proxy instantiation compatible with ProxyManager 2.x by detecting proxy features #17676 - making the proxy instantiation compatible with ProxyManager 2.x by detecting proxy features Fix bug when using an private aliased factory service [Form] fix tests added by #17798 by removing `choices_as_values` [Form] fix FQCN in tests added by #17798 [DependencyInjection] Remove unused parameter of private property bug #17798 [Form] allow `choice_label` option to be `false` [Form] fix tests added by #17760 with FQCN ChoiceFormField of type "select" could be "disabled" Update contributing docs [Console] Fix escaping of trailing backslashes Fix constraint validator alias being required [DependencyInjection] Simplified code in AutowirePass [ci] clone with depth=1 to kill push-forced PRs Add check on If-Range header
2 parents 338b4d2 + 9b5b55d commit 2fad429

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

Compiler/AutowirePass.php

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -148,45 +148,17 @@ private function populateAvailableType($id, Definition $definition)
148148
$this->types[$type] = $id;
149149
}
150150

151-
// Cannot use reflection if the class isn't set
152-
if (!$definition->getClass()) {
151+
if (!$reflectionClass = $this->getReflectionClass($id, $definition)) {
153152
return;
154153
}
155154

156-
if ($reflectionClass = $this->getReflectionClass($id, $definition)) {
157-
$this->extractInterfaces($id, $reflectionClass);
158-
$this->extractAncestors($id, $reflectionClass);
159-
}
160-
}
161-
162-
/**
163-
* Extracts the list of all interfaces implemented by a class.
164-
*
165-
* @param string $id
166-
* @param \ReflectionClass $reflectionClass
167-
*/
168-
private function extractInterfaces($id, \ReflectionClass $reflectionClass)
169-
{
170-
foreach ($reflectionClass->getInterfaces() as $interfaceName => $reflectionInterface) {
171-
$this->set($interfaceName, $id);
172-
173-
$this->extractInterfaces($id, $reflectionInterface);
155+
foreach ($reflectionClass->getInterfaces() as $reflectionInterface) {
156+
$this->set($reflectionInterface->name, $id);
174157
}
175-
}
176-
177-
/**
178-
* Extracts all inherited types of a class.
179-
*
180-
* @param string $id
181-
* @param \ReflectionClass $reflectionClass
182-
*/
183-
private function extractAncestors($id, \ReflectionClass $reflectionClass)
184-
{
185-
$this->set($reflectionClass->name, $id);
186158

187-
if ($reflectionParentClass = $reflectionClass->getParentClass()) {
188-
$this->extractAncestors($id, $reflectionParentClass);
189-
}
159+
do {
160+
$this->set($reflectionClass->name, $id);
161+
} while ($reflectionClass = $reflectionClass->getParentClass());
190162
}
191163

192164
/**
@@ -272,6 +244,7 @@ private function getReflectionClass($id, Definition $definition)
272244
return $this->reflectionClasses[$id];
273245
}
274246

247+
// Cannot use reflection if the class isn't set
275248
if (!$class = $definition->getClass()) {
276249
return;
277250
}

Dumper/PhpDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private function addServiceInlinedDefinitions($id, $definition)
315315
throw new ServiceCircularReferenceException($id, array($id));
316316
}
317317

318-
$code .= $this->addNewInstance($id, $sDefinition, '$'.$name, ' = ');
318+
$code .= $this->addNewInstance($sDefinition, '$'.$name, ' = ');
319319

320320
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
321321
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
@@ -389,7 +389,7 @@ private function addServiceInstance($id, $definition)
389389
$instantiation .= ' = ';
390390
}
391391

392-
$code = $this->addNewInstance($id, $definition, $return, $instantiation);
392+
$code = $this->addNewInstance($definition, $return, $instantiation);
393393

394394
if (!$simple) {
395395
$code .= "\n";
@@ -676,7 +676,7 @@ private function addServices()
676676
return $publicServices.$privateServices;
677677
}
678678

679-
private function addNewInstance($id, Definition $definition, $return, $instantiation)
679+
private function addNewInstance(Definition $definition, $return, $instantiation)
680680
{
681681
$class = $this->dumpValue($definition->getClass());
682682

Tests/Compiler/AutowirePassTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ public function testProcessAutowireInterface()
6161
$pass = new AutowirePass();
6262
$pass->process($container);
6363

64-
$this->assertCount(2, $container->getDefinition('g')->getArguments());
64+
$this->assertCount(3, $container->getDefinition('g')->getArguments());
6565
$this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(0));
6666
$this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(1));
67+
$this->assertEquals('f', (string) $container->getDefinition('g')->getArgument(2));
6768
}
6869

6970
public function testCompleteExistingDefinition()
@@ -332,13 +333,21 @@ interface EInterface extends DInterface
332333
{
333334
}
334335

335-
class F implements EInterface
336+
interface IInterface
337+
{
338+
}
339+
340+
class I implements IInterface
341+
{
342+
}
343+
344+
class F extends I implements EInterface
336345
{
337346
}
338347

339348
class G
340349
{
341-
public function __construct(DInterface $d, EInterface $e)
350+
public function __construct(DInterface $d, EInterface $e, IInterface $i)
342351
{
343352
}
344353
}

Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\DependencyInjection\Definition;
1717
use Symfony\Component\DependencyInjection\Reference;
1818

19+
require_once __DIR__.'/../Fixtures/includes/foo.php';
20+
1921
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
2022
{
2123
public function testProcess()
@@ -46,6 +48,26 @@ public function testProcess()
4648
$this->assertSame('b_alias', (string) $resolvedFactory[0]);
4749
}
4850

51+
/**
52+
* @group legacy
53+
*/
54+
public function testPrivateAliasesInFactory()
55+
{
56+
$container = new ContainerBuilder();
57+
58+
$container->register('a', 'FooClass');
59+
$container->register('b', 'FooClass')
60+
->setFactoryService('a')
61+
->setFactoryMethod('getInstance');
62+
63+
$container->register('c', 'stdClass')->setPublic(false);
64+
$container->setAlias('c_alias', 'c');
65+
66+
$this->process($container);
67+
68+
$this->assertInstanceOf('FooClass', $container->get('b'));
69+
}
70+
4971
/**
5072
* @expectedException \InvalidArgumentException
5173
*/

0 commit comments

Comments
 (0)