1
0
Fork 0

Ignore classes in ClassMapGenerator

pull/2948/head
Jordi Boggiano 2014-04-29 14:35:02 +02:00
parent 29c39cc266
commit 05d9912f97
2 changed files with 15 additions and 8 deletions

View File

@ -184,8 +184,9 @@ EOF;
preg_quote($dir), preg_quote($dir),
($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($namespace, '\\', '/')) : '' ($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)) { $namespaceFilter = $namespace === '' ? null : $namespace;
foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) {
if (!isset($classMap[$class])) { if (!isset($classMap[$class])) {
$path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
$classMap[$class] = $path.",\n"; $classMap[$class] = $path.",\n";
@ -195,7 +196,6 @@ EOF;
} }
} }
} }
}
foreach ($autoloads['classmap'] as $dir) { foreach ($autoloads['classmap'] as $dir) {
foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) { foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) {

View File

@ -46,12 +46,14 @@ class ClassMapGenerator
* *
* @param \Iterator|string $path The path to search in or an iterator * @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 * @return array A class map array
* *
* @throws \RuntimeException When the path is neither an existing file nor directory * @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_string($path)) {
if (is_file($path)) { if (is_file($path)) {
@ -82,6 +84,11 @@ class ClassMapGenerator
$classes = self::findClasses($filePath); $classes = self::findClasses($filePath);
foreach ($classes as $class) { foreach ($classes as $class) {
// skip classes not within the given namespace prefix
if (null !== $namespace && 0 !== strpos($class, $namespace)) {
continue;
}
if (!isset($map[$class])) { if (!isset($map[$class])) {
$map[$class] = $filePath; $map[$class] = $filePath;
} elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) { } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) {