Deduplicate classmap creation and add support for loading classmaps on the fly for plugins & co
parent
1698e50aff
commit
1160b782c8
|
@ -222,34 +222,14 @@ EOF;
|
||||||
);
|
);
|
||||||
|
|
||||||
$namespaceFilter = $namespace === '' ? null : $namespace;
|
$namespaceFilter = $namespace === '' ? null : $namespace;
|
||||||
foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) {
|
$classMap = $this->addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $whitelist, $namespaceFilter, $classMap);
|
||||||
$pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n";
|
|
||||||
if (!isset($classMap[$class])) {
|
|
||||||
$classMap[$class] = $pathCode;
|
|
||||||
} elseif ($this->io && $classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class].' '.$path, '\\', '/'))) {
|
|
||||||
$this->io->writeError(
|
|
||||||
'<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
|
|
||||||
' was found in both "'.str_replace(array('$vendorDir . \'', "',\n"), array($vendorPath, ''), $classMap[$class]).'" and "'.$path.'", the first will be used.</warning>'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($autoloads['classmap'] as $dir) {
|
foreach ($autoloads['classmap'] as $dir) {
|
||||||
foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) {
|
$classMap = $this->addClassMapCode($filesystem, $basePath, $vendorPath, $dir, null, null, $classMap);
|
||||||
$pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n";
|
|
||||||
if (!isset($classMap[$class])) {
|
|
||||||
$classMap[$class] = $pathCode;
|
|
||||||
} elseif ($this->io && $classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class].' '.$path, '\\', '/'))) {
|
|
||||||
$this->io->writeError(
|
|
||||||
'<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
|
|
||||||
' was found in both "'.str_replace(array('$vendorDir . \'', "',\n"), array($vendorPath, ''), $classMap[$class]).'" and "'.$path.'", the first will be used.</warning>'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($classMap);
|
ksort($classMap);
|
||||||
|
@ -297,6 +277,28 @@ EOF;
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $whitelist = null, $namespaceFilter = null, array $classMap = array())
|
||||||
|
{
|
||||||
|
foreach ($this->generateClassMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) {
|
||||||
|
$pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n";
|
||||||
|
if (!isset($classMap[$class])) {
|
||||||
|
$classMap[$class] = $pathCode;
|
||||||
|
} elseif ($this->io && $classMap[$class] !== $pathCode && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($classMap[$class].' '.$path, '\\', '/'))) {
|
||||||
|
$this->io->writeError(
|
||||||
|
'<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
|
||||||
|
' was found in both "'.str_replace(array('$vendorDir . \'', "',\n"), array($vendorPath, ''), $classMap[$class]).'" and "'.$path.'", the first will be used.</warning>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $classMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateClassMap($dir, $whitelist = null, $namespaceFilter = null)
|
||||||
|
{
|
||||||
|
return ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter);
|
||||||
|
}
|
||||||
|
|
||||||
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages)
|
public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages)
|
||||||
{
|
{
|
||||||
// build package => install path map
|
// build package => install path map
|
||||||
|
@ -386,6 +388,12 @@ EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($autoloads['classmap'])) {
|
||||||
|
foreach ($autoloads['classmap'] as $dir) {
|
||||||
|
$loader->addClassMap($this->generateClassMap($dir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue