Skip to content

Commit

Permalink
[ClassLoader] fixed order of interfaces in generated class collection…
Browse files Browse the repository at this point in the history
… caches (closes #4841)
  • Loading branch information
fabpot committed Jul 10, 2012
1 parent e83c1a5 commit 9a2c617
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Expand Up @@ -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;
Expand Down
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -45,6 +47,7 @@ public function getDifferentOrders()
array(array(
'ClassesWithParents\\A',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\GInterface',
'ClassesWithParents\\B',
)),
array(array(
Expand Down Expand Up @@ -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',
Expand Down
Expand Up @@ -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 9a2c617

Please sign in to comment.