using finder for classmap generator

main
Robert Schönthal 11 years ago
parent 0822683706
commit 4af410e1b9

@ -12,6 +12,7 @@
*/ */
namespace Composer\Autoload; namespace Composer\Autoload;
use Symfony\Component\Finder\Finder;
/** /**
* ClassMapGenerator * ClassMapGenerator
@ -53,7 +54,7 @@ class ClassMapGenerator
if (is_file($path)) { if (is_file($path)) {
$path = array(new \SplFileInfo($path)); $path = array(new \SplFileInfo($path));
} elseif (is_dir($path)) { } elseif (is_dir($path)) {
$path = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); $path = Finder::create()->files()->followLinks()->name('/.*[php|inc]/')->in($path);
} else { } else {
throw new \RuntimeException( throw new \RuntimeException(
'Could not scan for classes inside "'.$path. 'Could not scan for classes inside "'.$path.
@ -65,10 +66,6 @@ class ClassMapGenerator
$map = array(); $map = array();
foreach ($path as $file) { foreach ($path as $file) {
if (!$file->isFile()) {
continue;
}
$filePath = $file->getRealPath(); $filePath = $file->getRealPath();
if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) { if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc'))) {
@ -84,7 +81,6 @@ class ClassMapGenerator
foreach ($classes as $class) { foreach ($classes as $class) {
$map[$class] = $filePath; $map[$class] = $filePath;
} }
} }
return $map; return $map;
@ -102,7 +98,11 @@ class ClassMapGenerator
$traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait'; $traits = version_compare(PHP_VERSION, '5.4', '<') ? '' : '|trait';
try { try {
$contents = php_strip_whitespace($path); if (!is_readable($path)) {
throw new \RuntimeException('file not found');
}
//suppress warnings on unclosed comments
$contents = @php_strip_whitespace($path);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e); throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e);
} }

Loading…
Cancel
Save