1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 17:12:51 +00:00

Make sure target-dir plays well with classmap and files autoload, for root and deps, refs #1550

This commit is contained in:
Jordi Boggiano 2013-02-19 15:23:43 +01:00
parent ab1256e135
commit 5a484cb3a9
4 changed files with 85 additions and 45 deletions

View file

@ -450,25 +450,34 @@ FOOTER;
if (!isset($autoload[$type]) || !is_array($autoload[$type])) {
continue;
}
if ($type !== 'files' && null !== $package->getTargetDir() && $package !== $mainPackage) {
if (null !== $package->getTargetDir() && $package !== $mainPackage) {
$installPath = substr($installPath, 0, -strlen('/'.$package->getTargetDir()));
}
foreach ($autoload[$type] as $namespace => $paths) {
foreach ((array) $paths as $path) {
// remove target-dir from file paths
if ($type === 'files' && !is_readable($installPath.$path)) {
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
// remove target-dir from file paths of the root package
if ($type === 'files' && $package === $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
$path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/');
}
// add target-dir from file paths that don't have it
if ($type === 'files' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
$path = $package->getTargetDir() . '/' . $path;
}
// remove target-dir from classmap entries of the root package
if ($type === 'classmap' && $package === $mainPackage && $package->getTargetDir()) {
if ($type === 'classmap' && $package === $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
$path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/');
}
// add target-dir to classmap entries that don't have it
if ($type === 'classmap' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
$path = $package->getTargetDir() . '/' . $path;
}
$autoloads[$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
}
}