From 05d9912f97a2decf6a5c08dfa569dcf23d79b16d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 29 Apr 2014 14:35:02 +0200 Subject: [PATCH] Ignore classes in ClassMapGenerator --- src/Composer/Autoload/AutoloadGenerator.php | 12 ++++++------ src/Composer/Autoload/ClassMapGenerator.php | 11 +++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 20f8c7570..1f446c58b 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -184,12 +184,12 @@ EOF; preg_quote($dir), ($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($namespace, '\\', '/')) : '' ); - foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io) as $class => $path) { - if ('' === $namespace || 0 === strpos($class, $namespace)) { - if (!isset($classMap[$class])) { - $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); - $classMap[$class] = $path.",\n"; - } + + $namespaceFilter = $namespace === '' ? null : $namespace; + foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) { + if (!isset($classMap[$class])) { + $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); + $classMap[$class] = $path.",\n"; } } } diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 924a930c7..7b977cd3d 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -45,13 +45,15 @@ class ClassMapGenerator * Iterate over all files in the given directory searching for classes * * @param \Iterator|string $path The path to search in or an iterator - * @param string $whitelist Regex that matches against the file path + * @param string $whitelist Regex that matches against the file path + * @param IOInterface $io IO object + * @param string $namespace Optional namespace prefix to filter by * * @return array A class map array * * @throws \RuntimeException When the path is neither an existing file nor directory */ - public static function createMap($path, $whitelist = null, IOInterface $io = null) + public static function createMap($path, $whitelist = null, IOInterface $io = null, $namespace = null) { if (is_string($path)) { if (is_file($path)) { @@ -82,6 +84,11 @@ class ClassMapGenerator $classes = self::findClasses($filePath); foreach ($classes as $class) { + // skip classes not within the given namespace prefix + if (null !== $namespace && 0 !== strpos($class, $namespace)) { + continue; + } + if (!isset($map[$class])) { $map[$class] = $filePath; } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) {