8000 merged branch hason/classloader (PR #3529) · symfony/symfony@d2d7aec · GitHub
[go: up one dir, main page]

Skip to content

Commit d2d7aec

Browse files
committed
merged branch hason/classloader (PR #3529)
Commits ------- 1ec075d [ClassLoader] Fixed version compare 8fb529c [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
2 parents 2d65e17 + 1ec075d commit d2d7aec

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static private function findClasses($path)
8484
{
8585
$contents = file_get_contents($path);
8686
$tokens = token_get_all($contents);
87+
$T_TRAIT = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;
8788

8889
$classes = array();
8990

@@ -110,6 +111,7 @@ static private function findClasses($path)
110111
break;
111112
case T_CLASS:
112113
case T_INTERFACE:
114+
case $T_TRAIT:
113115
// Find the classname
114116
while (($t = $tokens[++$i]) && is_array($t)) {
115117
if (T_STRING === $t[0]) {
@@ -119,11 +121,7 @@ static private function findClasses($path)
119121
}
120122
}
121123

122-
if (empty($namespace)) {
123-
$classes[] = $class;
124-
} else {
125-
$classes[] = $namespace . $class;
126-
}
124+
$classes[] = ltrim($namespace . $class, '\\');
127125
break;
128126
default:
129127
break;

tests/Symfony/Tests/Component/ClassLoader/ClassMapGeneratorTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testCreateMap($directory, $expected)
2626

2727
public function getTestCreateMapTests()
2828
{
29-
return array(
29+
$data = array(
3030
array(__DIR__.'/Fixtures/Namespaced', array(
3131
'Namespaced\\Bar' => realpath(__DIR__).'/Fixtures/Namespaced/Bar.php',
3232
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
@@ -45,6 +45,7 @@ public function getTestCreateMapTests()
4545
array(__DIR__.'/Fixtures/classmap', array(
4646
'Foo\\Bar\\A' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
4747
'Foo\\Bar\\B' => realpath(__DIR__).'/Fixtures/classmap/sameNsMultipleClasses.php',
48+
'A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
4849
'Alpha\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
4950
'Alpha\\B' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
5051
'Beta\\A' => realpath(__DIR__).'/Fixtures/classmap/multipleNs.php',
@@ -54,6 +55,19 @@ public function getTestCreateMapTests()
5455
'ClassMap\\SomeClass' => realpath(__DIR__).'/Fixtures/classmap/SomeClass.php',
5556
)),
5657
);
58+
59+
if (version_compare(PHP_VERSION, '5.4', '>=')) {
60+
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
61+
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
62+
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
63+
'Foo\\TBar' => __DIR__.'/Fixtures/php5.4/traits.php',
64+
'Foo\\IBar' => __DIR__.'/Fixtures/php5.4/traits.php',
65+
'Foo\\TFooBar' => __DIR__.'/Fixtures/php5.4/traits.php',
66+
'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php',
67+
));
68+
}
69+
70+
return $data;
5771
}
5872

5973
public function testCreateMapFinderSupport()

tests/Symfony/Tests/Component/ClassLoader/Fixtures/classmap/multipleNs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
namespace {
3+
class A {}
4+
}
25

36
namespace Alpha {
47
class A {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace {
3+
trait TFoo {
4+
5+
}
6+
7+
class CFoo {
8+
use TFoo;
9+
}
10+
}
11+
12+
namespace Foo {
13+
trait TBar {
14+
15+
}
16+
17+
interface IBar {
18+
19+
}
20+
21+
trait TFooBar {
22+
23+
}
24+
25+
class CBar implements IBar {
26+
use TBar, TFooBar;
27+
}
28+
}

0 commit comments

Comments
 (0)
0