Skip to content

Commit 32aa36d

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [Form] fix FQCN in tests added by #17798 bug #17798 [Form] allow `choice_label` option to be `false` [DependencyInjection] Simplified code in AutowirePass
2 parents 694b13b + 3058f2c commit 32aa36d

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
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
/**
@@ -256,6 +228,7 @@ private function getReflectionClass($id, Definition $definition)
256228
return $this->reflectionClasses[$id];
257229
}
258230

231+
// Cannot use reflection if the class isn't set
259232
if (!$class = $definition->getClass()) {
260233
return;
261234
}

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()
@@ -317,13 +318,21 @@ interface EInterface extends DInterface
317318
{
318319
}
319320

320-
class F implements EInterface
321+
interface IInterface
322+
{
323+
}
324+
325+
class I implements IInterface
326+
{
327+
}
328+
329+
class F extends I implements EInterface
321330
{
322331
}
323332

324333
class G
325334
{
326-
public function __construct(DInterface $d, EInterface $e)
335+
public function __construct(DInterface $d, EInterface $e, IInterface $i)
327336
{
328337
}
329338
}

0 commit comments

Comments
 (0)