diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index f8f18fc28..862e44ba2 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -112,7 +112,10 @@ class ClassMapGenerator */ private static function findClasses($path) { - $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; + $extraTypes = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; + if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { + $extraTypes .= '|enum'; + } try { $contents = @php_strip_whitespace($path); @@ -129,7 +132,7 @@ class ClassMapGenerator } // return early if there is no chance of matching anything in this file - if (!preg_match('{\b(?:class|interface'.$traits.')\s}i', $contents)) { + if (!preg_match('{\b(?:class|interface'.$extraTypes.')\s}i', $contents)) { return array(); } @@ -154,7 +157,7 @@ class ClassMapGenerator preg_match_all('{ (?: - \b(?])(?Pclass|interface'.$traits.') \s+ (?P[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*) + \b(?])(?Pclass|interface'.$extraTypes.') \s+ (?P[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*) | \b(?])(?Pnamespace) (?P\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?:\s*\\\\\s*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*)? \s*[\{;] ) }ix', $contents, $matches); @@ -170,6 +173,12 @@ class ClassMapGenerator if ($name[0] === ':') { // This is an XHP class, https://github.com/facebook/xhp $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); + } else if ($matches['type'][$i] === 'enum') { + // In Hack, something like: + // enum Foo: int { HERP = '123'; } + // The regex above captures the colon, which isn't part of + // the class name. + $name = rtrim($name, ':'); } $classes[] = ltrim($namespace . $name, '\\'); } diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 81f99e57b..b8efc0c80 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -74,6 +74,13 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase 'Foo\\CBar' => __DIR__.'/Fixtures/php5.4/traits.php', )); } + if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { + $data[] = array(__DIR__.'/Fixtures/hhvm3.3', array( + 'FooEnum' => __DIR__.'/Fixtures/hhvm3.3/HackEnum.php', + 'Foo\BarEnum' => __DIR__.'/Fixtures/hhvm3.3/NamespacedHackEnum.php', + 'GenericsClass' => __DIR__.'/Fixtures/hhvm3.3/Generics.php', + )); + } return $data; } diff --git a/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/Generics.php b/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/Generics.php new file mode 100644 index 000000000..e5d1aa12a --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/Generics.php @@ -0,0 +1,4 @@ + { +} diff --git a/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/HackEnum.php b/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/HackEnum.php new file mode 100644 index 000000000..4b8dbfd40 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/hhvm3.3/HackEnum.php @@ -0,0 +1,6 @@ +