1
0
Fork 0

Merge remote-tracking branch 'cmodijk/master'

pull/1598/merge
Jordi Boggiano 2013-02-19 14:21:31 +01:00
commit ab1256e135
3 changed files with 20 additions and 2 deletions

View File

@ -450,12 +450,19 @@ FOOTER;
if (!isset($autoload[$type]) || !is_array($autoload[$type])) {
continue;
}
if (null !== $package->getTargetDir() && $package !== $mainPackage) {
if ($type !== 'files' && 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())));
$path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/');
}
// remove target-dir from classmap entries of the root package
if ($type === 'classmap' && $package === $mainPackage && $package->getTargetDir()) {
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));

View File

@ -64,7 +64,8 @@ class AutoloadGeneratorTest extends TestCase
$this->im->expects($this->any())
->method('getInstallPath')
->will($this->returnCallback(function ($package) use ($that) {
return $that->vendorDir.'/'.$package->getName();
$targetDir = $package->getTargetDir();
return $that->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
}));
$this->repository = $this->getMock('Composer\Repository\RepositoryInterface');
@ -318,8 +319,11 @@ class AutoloadGeneratorTest extends TestCase
$packages = array();
$packages[] = $a = new Package('a/a', '1.0', '1.0');
$packages[] = $b = new Package('b/b', '1.0', '1.0');
$packages[] = $c = new Package('c/c', '1.0', '1.0');
$a->setAutoload(array('files' => array('test.php')));
$b->setAutoload(array('files' => array('test2.php')));
$c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
$c->setTargetDir('foo/bar');
$this->repository->expects($this->once())
->method('getPackages')
@ -327,8 +331,11 @@ class AutoloadGeneratorTest extends TestCase
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
$this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
@ -338,6 +345,8 @@ class AutoloadGeneratorTest extends TestCase
include $this->vendorDir . '/autoload.php';
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
$this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
$this->assertTrue(function_exists('testFilesAutoloadGeneration3'));
$this->assertTrue(function_exists('testFilesAutoloadGeneration4'));
$this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
}

View File

@ -40,7 +40,9 @@ class ComposerAutoloaderInitFilesAutoload
require $vendorDir . '/a/a/test.php';
require $vendorDir . '/b/b/test2.php';
require $vendorDir . '/c/c/foo/bar/test3.php';
require $baseDir . '/root.php';
require $vendorDir . '/c/c/foo/bar/test4.php';
return $loader;
}