Skip to content

Commit 9a2c617

Browse files
committed
[ClassLoader] fixed order of interfaces in generated class collection caches (closes #4841)
1 parent e83c1a5 commit 9a2c617

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,21 @@ private static function getClassHierarchy(\ReflectionClass $class)
283283
}
284284
}
285285

286+
return array_merge(self::getInterfaces($class), $classes);
287+
}
288+
289+
private static function getInterfaces(\ReflectionClass $class)
290+
{
291+
$classes = array();
292+
286293
foreach ($class->getInterfaces() as $interface) {
287-
if ($interface->isUserDefined() && !isset(self::$seen[$interface->getName()])) {
288-
self::$seen[$interface->getName()] = true;
294+
$classes = array_merge($classes, self::getInterfaces($interface));
295+
}
289296

290-
array_unshift($classes, $interface);
291-
}
297+
if ($class->isUserDefined() && $class->isInterface() && !isset(self::$seen[$class->getName()])) {
298+
self::$seen[$class->getName()] = true;
299+
300+
$classes[] = $class;
292301
}
293302

294303
return $classes;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\ClassLoader\ClassCollectionLoader;
1515

16+
require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
1617
require_once __DIR__.'/Fixtures/ClassesWithParents/CInterface.php';
1718
require_once __DIR__.'/Fixtures/ClassesWithParents/B.php';
1819
require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
@@ -25,6 +26,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
2526
public function testClassReordering(array $classes)
2627
{
2728
$expected = array(
29+
'ClassesWithParents\\GInterface',
2830
'ClassesWithParents\\CInterface',
2931
'ClassesWithParents\\B',
3032
'ClassesWithParents\\A',
@@ -45,6 +47,7 @@ public function getDifferentOrders()
4547
array(array(
4648
'ClassesWithParents\\A',
4749
'ClassesWithParents\\CInterface',
50+
'ClassesWithParents\\GInterface',
4851
'ClassesWithParents\\B',
4952
)),
5053
array(array(
@@ -81,6 +84,7 @@ public function testClassWithTraitsReordering(array $classes)
8184
require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
8285

8386
$expected = array(
87+
'ClassesWithParents\\GInterface',
8488
'ClassesWithParents\\CInterface',
8589
'ClassesWithParents\\CTrait',
8690
'ClassesWithParents\\ATrait',

src/Symfony/Component/ClassLoader/Tests/Fixtures/ClassesWithParents/CInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
namespace ClassesWithParents;
44

5-
interface CInterface {}
5+
interface CInterface extends GInterface
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace ClassesWithParents;
4+
5+
interface GInterface
6+
{
7+
}

0 commit comments

Comments
 (0)