From 4c3e7802a466ace1ad3f610dff27ed7471b8eddc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 10 Nov 2012 17:58:18 +0100 Subject: [PATCH] Fix traits on 5.3 and handling of empty namespace blocks --- src/Composer/Autoload/ClassMapGenerator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 521f84171..85e14768d 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -93,9 +93,10 @@ class ClassMapGenerator private static function findClasses($path) { $contents = php_strip_whitespace($path); + $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; try { - if (!preg_match('{\b(?:class|interface|trait)\b}i', $contents)) { + if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) { return array(); } @@ -104,7 +105,7 @@ class ClassMapGenerator // strip strings $contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}', 'null', $contents); - preg_match_all('{(?:\b(?])(?class|interface|trait)\s+(?\S+)|\b(?])(?namespace)\s+(?[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*))}i', $contents, $matches); + preg_match_all('{(?:\b(?])(?class|interface'.$traits.')\s+(?\S+)|\b(?])(?namespace)(?\s+[^\s;{}\\\\]+(?:\s*\\\\\s*[^\s;{}\\\\]+)*|\s*\{))}i', $contents, $matches); $classes = array(); $namespace = '';