8000 [ClassLoader] Fixed ClassMapGenerator and added suport for traits by hason · Pull Request #3529 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[ClassLoader] Fixed ClassMapGenerator and added suport for traits #3529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Symfony/Component/ClassLoader/ClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static private function findClasses($path)
{
$contents = file_get_contents($path);
$tokens = token_get_all($contents);
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;

$classes = array();

Expand All @@ -110,6 +111,7 @@ static private function findClasses($path)
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]) {
Expand All @@ -119,11 +121,7 @@ static private function findClasses($path)
}
}

if (empty($namespace)) {
$classes[] = $class;
} else {
$classes[] = $namespace . $class;
}
$classes[] = ltrim($namespace . $class, '\\');
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testCreateMap($directory, $expected)

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',
Expand All @@ -45,6 +45,7 @@ public function getTestCreateMapTests()
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',
Expand All @@ -54,6 +55,19 @@ public function getTestCreateMapTests()
'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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
namespace {
class A {}
}

namespace Alpha {
class A {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
0