Permalink
Browse files

[ClassLoader] fixed order of interfaces in generated class collection…

… caches (closes #4841)
  • Loading branch information...
fabpot committed Jul 10, 2012
1 parent 3a94e56 commit 9c929006d1ad521604a8ccaa2526ca6f2149913c
View
@@ -283,12 +283,21 @@ private static function getClassHierarchy(\ReflectionClass $class)
}
}
+ return array_merge(self::getInterfaces($class), $classes);
+ }
+
+ private static function getInterfaces(\ReflectionClass $class)
+ {
+ $classes = array();
+
foreach ($class->getInterfaces() as $interface) {
- if ($interface->isUserDefined() && !isset(self::$seen[$interface->getName()])) {
- self::$seen[$interface->getName()] = true;
+ $classes = array_merge($classes, self::getInterfaces($interface));
+ }
- array_unshift($classes, $interface);
- }
+ if ($class->isUserDefined() && $class->isInterface() && !isset(self::$seen[$class->getName()])) {
+ self::$seen[$class->getName()] = true;
+
+ $classes[] = $class;
}
return $classes;
@@ -13,6 +13,7 @@
use Symfony\Component\ClassLoader\ClassCollectionLoader;
+require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/CInterface.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/B.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
@@ -25,6 +26,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
public function testClassReordering(array $classes)
{
$expected = array(
+ 'ClassesWithParents\\GInterface',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\B',
'ClassesWithParents\\A',
@@ -45,6 +47,7 @@ public function getDifferentOrders()
array(array(
'ClassesWithParents\\A',
'ClassesWithParents\\CInterface',
+ 'ClassesWithParents\\GInterface',
'ClassesWithParents\\B',
)),
array(array(
@@ -81,6 +84,7 @@ public function testClassWithTraitsReordering(array $classes)
require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
$expected = array(
+ 'ClassesWithParents\\GInterface',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\CTrait',
'ClassesWithParents\\ATrait',
@@ -2,4 +2,6 @@
namespace ClassesWithParents;
-interface CInterface {}
+interface CInterface extends GInterface
+{
+}
@@ -0,0 +1,7 @@
+<?php
+
+namespace ClassesWithParents;
+
+interface GInterface
+{
+}

0 comments on commit 9c92900

Please sign in to comment.