[ClassLoader] fixed order of interfaces in generated class collection caches (closes #4841)

This commit is contained in:
Fabien Potencier 2012-07-10 20:27:54 +02:00
parent e83c1a590a
commit 9a2c61780b
4 changed files with 28 additions and 6 deletions

View File

@ -283,12 +283,21 @@ class ClassCollectionLoader
}
}
foreach ($class->getInterfaces() as $interface) {
if ($interface->isUserDefined() && !isset(self::$seen[$interface->getName()])) {
self::$seen[$interface->getName()] = true;
return array_merge(self::getInterfaces($class), $classes);
}
array_unshift($classes, $interface);
}
private static function getInterfaces(\ReflectionClass $class)
{
$classes = array();
foreach ($class->getInterfaces() as $interface) {
$classes = array_merge($classes, self::getInterfaces($interface));
}
if ($class->isUserDefined() && $class->isInterface() && !isset(self::$seen[$class->getName()])) {
self::$seen[$class->getName()] = true;
$classes[] = $class;
}
return $classes;

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\ClassLoader\Tests;
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 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
array(array(
'ClassesWithParents\\A',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\GInterface',
'ClassesWithParents\\B',
)),
array(array(
@ -81,6 +84,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
$expected = array(
'ClassesWithParents\\GInterface',
'ClassesWithParents\\CInterface',
'ClassesWithParents\\CTrait',
'ClassesWithParents\\ATrait',

View File

@ -2,4 +2,6 @@
namespace ClassesWithParents;
interface CInterface {}
interface CInterface extends GInterface
{
}

View File

@ -0,0 +1,7 @@
<?php
namespace ClassesWithParents;
interface GInterface
{
}