Skip to content

Commit cfdb925

Browse files
author
Szijarto Tamas
committed
[ClassLoader] Fix undefined index in ClassCollectionLoader
1 parent 15551f2 commit cfdb925

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,17 @@ private static function resolveDependencies(array $tree, $node, \ArrayObject $re
353353
$unresolved = new \ArrayObject();
354354
}
355355
$nodeName = $node->getName();
356-
$unresolved[$nodeName] = $node;
357-
foreach ($tree[$nodeName] as $dependency) {
358-
if (!$resolved->offsetExists($dependency->getName())) {
359-
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
356+
357+
if (isset($tree[$nodeName])) {
358+
$unresolved[$nodeName] = $node;
359+
foreach ($tree[$nodeName] as $dependency) {
360+
if (!$resolved->offsetExists($dependency->getName())) {
361+
self::resolveDependencies($tree, $dependency, $resolved, $unresolved);
362+
}
360363
}
364+
$resolved[$nodeName] = $node;
365+
unset($unresolved[$nodeName]);
361366
}
362-
$resolved[$nodeName] = $node;
363-
unset($unresolved[$nodeName]);
364367

365368
return $resolved;
366369
}

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,38 @@ public function getDifferentOrdersForTraits()
146146
);
147147
}
148148

149+
public function testFixClassWithTraitsOrdering()
150+
{
151+
if (PHP_VERSION_ID < 50400) {
152+
$this->markTestSkipped('Requires PHP > 5.4');
153+
154+
return;
155+
}
156+
157+
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
158+
require_once __DIR__.'/Fixtures/ClassesWithParents/F.php';
159+
require_once __DIR__.'/Fixtures/ClassesWithParents/G.php';
160+
161+
$classes = array(
162+
'ClassesWithParents\\F',
163+
'ClassesWithParents\\G',
164+
);
165+
166+
$expected = array(
167+
'ClassesWithParents\\CTrait',
168+
'ClassesWithParents\\F',
169+
'ClassesWithParents\\G',
170+
);
171+
172+
$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
173+
$m = $r->getMethod('getOrderedClasses');
174+
$m->setAccessible(true);
175+
176+
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
177+
178+
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
179+
}
180+
149181
/**
150182
* @dataProvider getFixNamespaceDeclarationsData
151183
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ClassesWithParents;
4+
5+
class F
6+
{
7+
use CTrait;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ClassesWithParents;
4+
5+
class G
6+
{
7+
use CTrait;
8+
}

0 commit comments

Comments
 (0)