merged branch hason/classloader (PR #3529)
Commits -------1ec075d
[ClassLoader] Fixed version compare8fb529c
[ClassLoader] Fixed ClassMapGenerator and added suport for traits Discussion ---------- [ClassLoader] Fixed ClassMapGenerator and added suport for traits --------------------------------------------------------------------------- by hason at 2012-03-08T10:49:53Z @fabpot, @Seldaek ``PHP_VERSION_ID`` or ``version_compare``? --------------------------------------------------------------------------- by Seldaek at 2012-03-08T11:42:20Z Ultimately @fabpot can call it, but I'm pro version_compare because it's just typically used for those checks, which may not make it more readable but makes it less WTF since it's a common pattern. --------------------------------------------------------------------------- by drak at 2012-03-08T13:43:18Z I prefer `version_compare()` with `phpversion()` as it's way more readable and obvious what it is. --------------------------------------------------------------------------- by fabpot at 2012-03-08T17:06:25Z +1 for `version_compare()` --------------------------------------------------------------------------- by hason at 2012-03-09T07:19:10Z @fabpot done
This commit is contained in:
commit
d2d7aecb64
@ -84,6 +84,7 @@ class ClassMapGenerator
|
||||
{
|
||||
$contents = file_get_contents($path);
|
||||
$tokens = token_get_all($contents);
|
||||
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;
|
||||
|
||||
$classes = array();
|
||||
|
||||
@ -110,6 +111,7 @@ class ClassMapGenerator
|
||||
break;
|
||||
case T_CLASS:
|
||||
case T_INTERFACE:
|
||||
case $T_TRAIT:
|
||||
// Find the classname
|
||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||
if (T_STRING === $t[0]) {
|
||||
@ -119,11 +121,7 @@ class ClassMapGenerator
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($namespace)) {
|
||||
$classes[] = $class;
|
||||
} else {
|
||||
$classes[] = $namespace . $class;
|
||||
}
|
||||
$classes[] = ltrim($namespace . $class, '\\');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -26,7 +26,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function getTestCreateMapTests()
|
||||
{
|
||||
return array(
|
||||
$data = array(
|
||||
array(__DIR__.'/Fixtures/Namespaced', array(
|
||||
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
|
||||
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
|
||||
@ -45,6 +45,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
array(__DIR__.'/Fixtures/classmap', array(
|
||||
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
|
||||
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
|
||||
@ -54,6 +55,19 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
||||
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
|
||||
)),
|
||||
);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4', '>=')) {
|
||||
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
|
||||
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
|
||||
));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testCreateMapFinderSupport()
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
namespace {
|
||||
class A {}
|
||||
}
|
||||
|
||||
namespace Alpha {
|
||||
class A {}
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace {
|
||||
trait TFoo {
|
||||
|
||||
}
|
||||
|
||||
class CFoo {
|
||||
use TFoo;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Foo {
|
||||
trait TBar {
|
||||
|
||||
}
|
||||
|
||||
interface IBar {
|
||||
|
||||
}
|
||||
|
||||
trait TFooBar {
|
||||
|
||||
}
|
||||
|
||||
class CBar implements IBar {
|
||||
use TBar, TFooBar;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user