Move composer metafiles back in a composer dir, except autoload.php
parent
870d745475
commit
15ab5868a3
|
@ -3,7 +3,7 @@
|
|||
* Schema: Added 'require-dev' for development-time requirements (tests, etc), install with --dev
|
||||
* Schema: Removed 'recommend'
|
||||
* Schema: 'suggest' is now informational and can use any description for a package, not only a constraint
|
||||
* Break: .composer/autoload.php and other files in vendor/.composer have been moved to vendor/
|
||||
* Break: vendor/.composer/autoload.php has been moved to vendor/autoload.php, other files are now in vendor/composer/
|
||||
* Added caching of repository metadata (faster startup times & failover if packagist is down)
|
||||
* Added include_path support for legacy projects that are full of require_once statements
|
||||
* Added installation notifications API to allow better statistics on Composer repositories
|
||||
|
|
|
@ -32,7 +32,8 @@ class AutoloadGenerator
|
|||
$filesystem->ensureDirectoryExists($targetDir);
|
||||
$vendorPath = strtr(realpath($installationManager->getVendorPath()), '\\', '/');
|
||||
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
|
||||
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
||||
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
||||
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
|
||||
|
||||
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
||||
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
|
||||
|
@ -42,7 +43,7 @@ class AutoloadGenerator
|
|||
|
||||
// autoload_namespace.php generated by Composer
|
||||
|
||||
\$vendorDir = $vendorDirCode;
|
||||
\$vendorDir = $vendorPathCode;
|
||||
\$baseDir = $appBaseDirCode;
|
||||
|
||||
return array(
|
||||
|
@ -72,7 +73,7 @@ EOF;
|
|||
|
||||
// autoload_classmap.php generated by Composer
|
||||
|
||||
\$vendorDir = $vendorDirCode;
|
||||
\$vendorDir = $vendorPathCode;
|
||||
\$baseDir = $appBaseDirCode;
|
||||
|
||||
return array(
|
||||
|
@ -91,12 +92,13 @@ EOF;
|
|||
|
||||
$targetDirLoader = <<<EOF
|
||||
spl_autoload_register(function(\$class) {
|
||||
\$prefixes = array($prefixes);
|
||||
static \$dir = $baseDirFromTargetDirCode . '/';
|
||||
static \$prefixes = array($prefixes);
|
||||
foreach (\$prefixes as \$prefix) {
|
||||
if (0 !== strpos(\$class, \$prefix)) {
|
||||
continue;
|
||||
}
|
||||
\$path = $baseDirFromTargetDirCode . '/' . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
||||
\$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
||||
if (!stream_resolve_include_path(\$path)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -121,21 +123,21 @@ EOF;
|
|||
|
||||
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
||||
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
||||
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorDirCode, $appBaseDirCode)) {
|
||||
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)) {
|
||||
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
||||
}
|
||||
file_put_contents($targetDir.'/autoload.php', $this->getAutoloadFile(true, true, (Boolean) $includePathFile, $targetDirLoader));
|
||||
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (Boolean) $includePathFile, $targetDirLoader));
|
||||
copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
|
||||
|
||||
// TODO BC feature, add E_DEPRECATED in autoload.php on April 30th, remove after May 30th
|
||||
if ($bcLinks) {
|
||||
$filesystem->ensureDirectoryExists($targetDir.'/.composer');
|
||||
file_put_contents($targetDir.'/.composer/autoload_namespaces.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload_namespaces.php';\n");
|
||||
file_put_contents($targetDir.'/.composer/autoload_classmap.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload_classmap.php';\n");
|
||||
file_put_contents($targetDir.'/.composer/autoload.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload.php';\n");
|
||||
file_put_contents($targetDir.'/.composer/ClassLoader.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/ClassLoader.php';\n");
|
||||
$filesystem->ensureDirectoryExists($vendorPath.'/.composer');
|
||||
file_put_contents($vendorPath.'/.composer/autoload_namespaces.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/composer/autoload_namespaces.php';\n");
|
||||
file_put_contents($vendorPath.'/.composer/autoload_classmap.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/composer/autoload_classmap.php';\n");
|
||||
file_put_contents($vendorPath.'/.composer/autoload.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/autoload.php';\n");
|
||||
file_put_contents($vendorPath.'/.composer/ClassLoader.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/composer/ClassLoader.php';\n");
|
||||
if ($includePathFile) {
|
||||
file_put_contents($targetDir.'/.composer/include_paths.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/include_paths.php';\n");
|
||||
file_put_contents($vendorPath.'/.composer/include_paths.php', "<?php\n// Deprecated file, use the one in root of vendor dir\nreturn include dirname(__DIR__).'/composer/include_paths.php';\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +215,7 @@ EOF;
|
|||
return $loader;
|
||||
}
|
||||
|
||||
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $relVendorPath, $vendorPath, $vendorDirCode, $appBaseDirCode)
|
||||
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)
|
||||
{
|
||||
$includePaths = array();
|
||||
|
||||
|
@ -239,7 +241,7 @@ EOF;
|
|||
|
||||
// include_paths.php generated by Composer
|
||||
|
||||
\$vendorDir = $vendorDirCode;
|
||||
\$vendorDir = $vendorPathCode;
|
||||
\$baseDir = $appBaseDirCode;
|
||||
|
||||
return array(
|
||||
|
@ -273,25 +275,26 @@ EOF;
|
|||
return $baseDir.var_export($path, true);
|
||||
}
|
||||
|
||||
protected function getAutoloadFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader)
|
||||
protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader)
|
||||
{
|
||||
$file = <<<'HEADER'
|
||||
$file = <<<HEADER
|
||||
<?php
|
||||
|
||||
// autoload.php generated by Composer
|
||||
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
||||
require __DIR__.'/ClassLoader.php';
|
||||
if (!class_exists('Composer\\\\Autoload\\\\ClassLoader', false)) {
|
||||
require $vendorPathToTargetDirCode . '/ClassLoader.php';
|
||||
}
|
||||
|
||||
return call_user_func(function() {
|
||||
$loader = new \Composer\Autoload\ClassLoader();
|
||||
\$loader = new \\Composer\\Autoload\\ClassLoader();
|
||||
\$composerDir = $vendorPathToTargetDirCode;
|
||||
|
||||
|
||||
HEADER;
|
||||
|
||||
if ($useIncludePath) {
|
||||
$file .= <<<'INCLUDE_PATH'
|
||||
$includePaths = require __DIR__.'/include_paths.php';
|
||||
$includePaths = require $composerDir . '/include_paths.php';
|
||||
array_unshift($includePaths, get_include_path());
|
||||
set_include_path(join(PATH_SEPARATOR, $includePaths));
|
||||
|
||||
|
@ -301,7 +304,7 @@ INCLUDE_PATH;
|
|||
|
||||
if ($usePSR0) {
|
||||
$file .= <<<'PSR0'
|
||||
$map = require __DIR__.'/autoload_namespaces.php';
|
||||
$map = require $composerDir . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->add($namespace, $path);
|
||||
}
|
||||
|
@ -312,7 +315,7 @@ PSR0;
|
|||
|
||||
if ($useClassMap) {
|
||||
$file .= <<<'CLASSMAP'
|
||||
$classMap = require __DIR__.'/autoload_classmap.php';
|
||||
$classMap = require $composerDir . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
|
|
|
@ -81,10 +81,10 @@ class Compiler
|
|||
$this->addFile($phar, $file);
|
||||
}
|
||||
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/ClassLoader.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload_namespaces.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload_classmap.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_namespaces.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_classmap.php'));
|
||||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/ClassLoader.php'));
|
||||
$this->addComposerBin($phar);
|
||||
|
||||
// Stubs
|
||||
|
|
|
@ -153,13 +153,23 @@ class Factory
|
|||
{
|
||||
// TODO BC feature, remove after May 30th
|
||||
if (file_exists($vendorDir.'/.composer/installed.json')) {
|
||||
rename($vendorDir.'/.composer/installed.json', $vendorDir.'/installed.json');
|
||||
if (!is_dir($vendorDir.'/composer')) { mkdir($vendorDir.'/composer/', 0777, true); }
|
||||
rename($vendorDir.'/.composer/installed.json', $vendorDir.'/composer/installed.json');
|
||||
}
|
||||
if (file_exists($vendorDir.'/.composer/installed_dev.json')) {
|
||||
rename($vendorDir.'/.composer/installed_dev.json', $vendorDir.'/installed_dev.json');
|
||||
if (!is_dir($vendorDir.'/composer')) { mkdir($vendorDir.'/composer/', 0777, true); }
|
||||
rename($vendorDir.'/.composer/installed_dev.json', $vendorDir.'/composer/installed_dev.json');
|
||||
}
|
||||
$rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/installed.json')));
|
||||
$rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/installed_dev.json')));
|
||||
if (file_exists($vendorDir.'/installed.json')) {
|
||||
if (!is_dir($vendorDir.'/composer')) { mkdir($vendorDir.'/composer/', 0777, true); }
|
||||
rename($vendorDir.'/installed.json', $vendorDir.'/composer/installed.json');
|
||||
}
|
||||
if (file_exists($vendorDir.'/installed_dev.json')) {
|
||||
if (!is_dir($vendorDir.'/composer')) { mkdir($vendorDir.'/composer/', 0777, true); }
|
||||
rename($vendorDir.'/installed_dev.json', $vendorDir.'/composer/installed_dev.json');
|
||||
}
|
||||
$rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed.json')));
|
||||
$rm->setLocalDevRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/composer/installed_dev.json')));
|
||||
}
|
||||
|
||||
protected function addPackagistRepository(array $localConfig)
|
||||
|
|
|
@ -174,7 +174,7 @@ class Installer
|
|||
$this->io->write('<info>Generating autoload files</info>');
|
||||
$generator = new AutoloadGenerator;
|
||||
$localRepos = new CompositeRepository($this->repositoryManager->getLocalRepositories());
|
||||
$generator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath(), true);
|
||||
$generator->dump($localRepos, $this->package, $this->installationManager, $this->installationManager->getVendorPath() . '/composer', true);
|
||||
|
||||
// dispatch post event
|
||||
$eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
|
||||
|
|
|
@ -60,14 +60,14 @@ class AutoloadGeneratorTest extends TestCase
|
|||
protected function tearDown()
|
||||
{
|
||||
if ($this->vendorDir === $this->workingDir) {
|
||||
if (is_dir($this->workingDir.'/.composer')) {
|
||||
$this->fs->removeDirectory($this->workingDir.'/.composer');
|
||||
if (is_dir($this->workingDir.'/composer')) {
|
||||
$this->fs->removeDirectory($this->workingDir.'/composer');
|
||||
}
|
||||
} elseif (is_dir($this->vendorDir)) {
|
||||
$this->fs->removeDirectory($this->vendorDir);
|
||||
}
|
||||
if (is_dir($this->workingDir.'/.composersrc')) {
|
||||
$this->fs->removeDirectory($this->workingDir.'/.composersrc');
|
||||
if (is_dir($this->workingDir.'/composersrc')) {
|
||||
$this->fs->removeDirectory($this->workingDir.'/composersrc');
|
||||
}
|
||||
|
||||
chdir($this->dir);
|
||||
|
@ -78,22 +78,22 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||
$package->setAutoload(array(
|
||||
'psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')),
|
||||
'classmap' => array('.composersrc/'),
|
||||
'classmap' => array('composersrc/'),
|
||||
));
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('getPackages')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
if (!is_dir($this->vendorDir.'/.composer')) {
|
||||
mkdir($this->vendorDir.'/.composer');
|
||||
if (!is_dir($this->vendorDir.'/composer')) {
|
||||
mkdir($this->vendorDir.'/composer');
|
||||
}
|
||||
|
||||
$this->createClassFile($this->workingDir);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('main', $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/.composer', 'classmap');
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
||||
public function testVendorDirSameAsWorkingDir()
|
||||
|
@ -103,22 +103,22 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||
$package->setAutoload(array(
|
||||
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
|
||||
'classmap' => array('.composersrc/'),
|
||||
'classmap' => array('composersrc/'),
|
||||
));
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('getPackages')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
if (!is_dir($this->vendorDir.'/.composer')) {
|
||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
if (!is_dir($this->vendorDir.'/composer')) {
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
}
|
||||
|
||||
$this->createClassFile($this->vendorDir);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('main3', $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/.composer', 'classmap');
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
||||
public function testMainPackageAutoloadingAlternativeVendorDir()
|
||||
|
@ -126,7 +126,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$package = new MemoryPackage('a', '1.0', '1.0');
|
||||
$package->setAutoload(array(
|
||||
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
|
||||
'classmap' => array('.composersrc/'),
|
||||
'classmap' => array('composersrc/'),
|
||||
));
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
|
@ -134,11 +134,11 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->will($this->returnValue(array()));
|
||||
|
||||
$this->vendorDir .= '/subdir';
|
||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->createClassFile($this->workingDir);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('main2', $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/.composer', 'classmap');
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
||||
public function testMainPackageAutoloadingWithTargetDir()
|
||||
|
@ -153,8 +153,8 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/.composer/autoload.php');
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
|
||||
}
|
||||
|
||||
public function testVendorsAutoloading()
|
||||
|
@ -171,10 +171,10 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/.composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/.composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
|
||||
}
|
||||
|
||||
public function testVendorsClassMapAutoloading()
|
||||
|
@ -191,7 +191,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
@mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
@mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
mkdir($this->vendorDir.'/a/a/src', 0777, true);
|
||||
mkdir($this->vendorDir.'/b/b/src', 0777, true);
|
||||
mkdir($this->vendorDir.'/b/b/lib', 0777, true);
|
||||
|
@ -199,17 +199,17 @@ class AutoloadGeneratorTest extends TestCase
|
|||
file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
|
||||
file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/.composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php',
|
||||
'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/src/b.php',
|
||||
'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/b/b/lib/c.php',
|
||||
),
|
||||
include ($this->vendorDir.'/.composer/autoload_classmap.php')
|
||||
include ($this->vendorDir.'/composer/autoload_classmap.php')
|
||||
);
|
||||
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/.composer', 'classmap');
|
||||
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
||||
public function testClassMapAutoloadingEmptyDirAndExactFile()
|
||||
|
@ -228,7 +228,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
@mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
@mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
mkdir($this->vendorDir.'/a/a/src', 0777, true);
|
||||
mkdir($this->vendorDir.'/b/b', 0777, true);
|
||||
mkdir($this->vendorDir.'/c/c/foo', 0777, true);
|
||||
|
@ -236,17 +236,17 @@ class AutoloadGeneratorTest extends TestCase
|
|||
file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
|
||||
file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/.composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php',
|
||||
'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/test.php',
|
||||
'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/c/c/foo/test.php',
|
||||
),
|
||||
include ($this->vendorDir.'/.composer/autoload_classmap.php')
|
||||
include ($this->vendorDir.'/composer/autoload_classmap.php')
|
||||
);
|
||||
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/.composer', 'classmap');
|
||||
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
|
||||
}
|
||||
|
||||
public function testOverrideVendorsAutoloading()
|
||||
|
@ -264,9 +264,9 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method('getPackages')
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir.'/.composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
|
||||
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/.composer');
|
||||
mkdir($this->vendorDir.'/composer', 0777, true);
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/composer');
|
||||
}
|
||||
|
||||
public function testIncludePathFileGeneration()
|
||||
|
@ -291,18 +291,18 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method("getPackages")
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir."/.composer", 0777, true);
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/.composer");
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/.composer/include_paths.php');
|
||||
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
$this->vendorDir."/a/a/lib",
|
||||
$this->vendorDir."/b/b/library",
|
||||
$this->vendorDir."/c/library",
|
||||
),
|
||||
require($this->vendorDir."/.composer/include_paths.php")
|
||||
require($this->vendorDir."/composer/include_paths.php")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -320,13 +320,13 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method("getPackages")
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir."/.composer", 0777, true);
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/.composer");
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
|
||||
$oldIncludePath = get_include_path();
|
||||
|
||||
require($this->vendorDir."/.composer/autoload.php");
|
||||
require($this->vendorDir."/autoload.php");
|
||||
|
||||
$this->assertEquals(
|
||||
$oldIncludePath.PATH_SEPARATOR.$this->vendorDir."/a/a/lib",
|
||||
|
@ -348,20 +348,20 @@ class AutoloadGeneratorTest extends TestCase
|
|||
->method("getPackages")
|
||||
->will($this->returnValue($packages));
|
||||
|
||||
mkdir($this->vendorDir."/.composer", 0777, true);
|
||||
mkdir($this->vendorDir."/composer", 0777, true);
|
||||
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/.composer");
|
||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir."/composer");
|
||||
|
||||
$this->assertFalse(file_exists($this->vendorDir."/.composer/include_paths.php"));
|
||||
$this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
|
||||
}
|
||||
|
||||
private function createClassFile($basedir)
|
||||
{
|
||||
if (!is_dir($basedir.'/.composersrc')) {
|
||||
mkdir($basedir.'/.composersrc', 0777, true);
|
||||
if (!is_dir($basedir.'/composersrc')) {
|
||||
mkdir($basedir.'/composersrc', 0777, true);
|
||||
}
|
||||
|
||||
file_put_contents($basedir.'/.composersrc/foo.php', '<?php class ClassMapFoo {}');
|
||||
file_put_contents($basedir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
||||
}
|
||||
|
||||
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
|
||||
|
|
|
@ -6,5 +6,5 @@ $vendorDir = dirname(__DIR__);
|
|||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
|
||||
'ClassMapFoo' => $baseDir . '/composersrc/foo.php',
|
||||
);
|
||||
|
|
|
@ -6,5 +6,5 @@ $vendorDir = dirname(__DIR__);
|
|||
$baseDir = dirname(dirname($vendorDir));
|
||||
|
||||
return array(
|
||||
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
|
||||
'ClassMapFoo' => $baseDir . '/composersrc/foo.php',
|
||||
);
|
||||
|
|
|
@ -6,5 +6,5 @@ $vendorDir = dirname(__DIR__);
|
|||
$baseDir = $vendorDir;
|
||||
|
||||
return array(
|
||||
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
|
||||
'ClassMapFoo' => $baseDir . '/composersrc/foo.php',
|
||||
);
|
||||
|
|
|
@ -2,29 +2,31 @@
|
|||
|
||||
// autoload.php generated by Composer
|
||||
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
||||
require __DIR__.'/ClassLoader.php';
|
||||
require __DIR__ . '/composer' . '/ClassLoader.php';
|
||||
}
|
||||
|
||||
return call_user_func(function() {
|
||||
$loader = new \Composer\Autoload\ClassLoader();
|
||||
$composerDir = __DIR__ . '/composer';
|
||||
|
||||
$map = require __DIR__.'/autoload_namespaces.php';
|
||||
$map = require $composerDir . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
$loader->add($namespace, $path);
|
||||
}
|
||||
|
||||
$classMap = require __DIR__.'/autoload_classmap.php';
|
||||
$classMap = require $composerDir . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
$loader->addClassMap($classMap);
|
||||
}
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
$prefixes = array('Main\\Foo', 'Main\\Bar');
|
||||
static $dir = dirname(dirname(__DIR__)) . '/';
|
||||
static $prefixes = array('Main\\Foo', 'Main\\Bar');
|
||||
foreach ($prefixes as $prefix) {
|
||||
if (0 !== strpos($class, $prefix)) {
|
||||
continue;
|
||||
}
|
||||
$path = dirname(dirname(__DIR__)) . '/' . implode('/', array_slice(explode('\\', $class), 2)).'.php';
|
||||
$path = $dir . implode('/', array_slice(explode('\\', $class), 2)).'.php';
|
||||
if (!stream_resolve_include_path($path)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue