diff --git a/.travis.yml b/.travis.yml index 17f966012..b47808025 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: before_script: - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini - - flags="" + - flags="--prefer-dist" - composer install $flags - bin/composer install $flags - git config --global user.name travis-ci diff --git a/appveyor.yml b/appveyor.yml index 7651c6da8..515c2e257 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,7 +28,7 @@ install: - IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat - appveyor DownloadFile https://getcomposer.org/composer.phar - cd c:\projects\composer - - composer install --prefer-source --no-progress + - composer install --prefer-dist --no-progress test_script: - cd c:\projects\composer diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 485183ac2..77a2a02fc 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -285,6 +285,7 @@ EOF; } file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)); + file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath)); $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE'); @@ -578,17 +579,26 @@ HEADER; INCLUDE_PATH; } + $file .= <<= 50600) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit$suffix::getInitializer(\$loader)); + } else { + +STATIC_INIT; + if (!$this->classMapAuthoritative) { $file .= <<<'PSR04' - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } PSR04; @@ -596,15 +606,16 @@ PSR04; if ($useClassMap) { $file .= <<<'CLASSMAP' - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } - + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } CLASSMAP; } + $file .= " }\n\n"; + if ($this->classMapAuthoritative) { $file .= <<<'CLASSMAPAUTHORITATIVE' $loader->setClassMapAuthoritative(true); @@ -635,7 +646,11 @@ REGISTER_LOADER; if ($useIncludeFiles) { $file .= <<= 50600) { + \$includeFiles = Composer\Autoload\ComposerStaticInit$suffix::\$files; + } else { + \$includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach (\$includeFiles as \$fileIdentifier => \$file) { composerRequire$suffix(\$fileIdentifier, \$file); } @@ -674,6 +689,84 @@ FOOTER; FOOTER; } + protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath) + { + $file = <<
$path) { + $loader->set($namespace, $path); + } + + $map = require $targetDir . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require $targetDir . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $filesystem = new Filesystem(); + + $vendorPathCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '"; + $appBaseDirCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '"; + + $absoluteVendorPathCode = ' ' . substr(var_export($vendorDir, true), 0, -1); + $absoluteAppBaseDirCode = ' ' . substr(var_export($baseDir, true), 0, -1); + + $initializer = ''; + $prefix = "\0Composer\Autoload\ClassLoader\0"; + $prefixLen = strlen($prefix); + if (file_exists($targetDir . '/autoload_files.php')) { + $maps = array('files' => require $targetDir . '/autoload_files.php'); + } else { + $maps = array(); + } + + foreach ((array) $loader as $prop => $value) { + if ($value && 0 === strpos($prop, $prefix)) { + $maps[substr($prop, $prefixLen)] = $value; + } + } + + foreach ($maps as $prop => $value) { + $value = var_export($value, true); + $value = str_replace($absoluteVendorPathCode, $vendorPathCode, $value); + $value = str_replace($absoluteAppBaseDirCode, $appBaseDirCode, $value); + $value = ltrim(preg_replace('/^ */m', ' $0$0', $value)); + + $file .= sprintf(" public static $%s = %s;\n\n", $prop, $value); + if ('files' !== $prop) { + $initializer .= " \$loader->$prop = ComposerStaticInit$suffix::\$$prop;\n"; + } + } + + return $file . <<addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_files.php')); $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_real.php')); + $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_static.php')); if (file_exists(__DIR__.'/../../vendor/composer/include_paths.php')) { $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/include_paths.php')); } diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index fd29d5218..e51b74105 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -358,10 +358,11 @@ class Filesystem * @param string $from * @param string $to * @param bool $directories if true, the source/target are considered to be directories + * @param bool $staticCode * @throws \InvalidArgumentException * @return string */ - public function findShortestPathCode($from, $to, $directories = false) + public function findShortestPathCode($from, $to, $directories = false, $staticCode = false) { if (!$this->isAbsolutePath($from) || !$this->isAbsolutePath($to)) { throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to)); @@ -388,7 +389,11 @@ class Filesystem return '__DIR__ . '.var_export(substr($to, strlen($from)), true); } $sourcePathDepth = substr_count(substr($from, strlen($commonPath)), '/') + $directories; - $commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth); + if ($staticCode) { + $commonPathCode = "__DIR__ . '".str_repeat('/..', $sourcePathDepth)."'"; + } else { + $commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth); + } $relTarget = substr($to, strlen($commonPath)); return $commonPathCode . (strlen($relTarget) ? '.' . var_export('/' . $relTarget, true) : ''); diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 07706c5d2..fafe59798 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -351,6 +351,7 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_target_dir.php', $this->vendorDir.'/composer/autoload_static.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php'); $this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap'); } @@ -580,6 +581,7 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions.php', $this->vendorDir.'/composer/autoload_static.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php'); include $this->vendorDir . '/autoload.php'; @@ -639,6 +641,7 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_static.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php'); $this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions.php', $this->vendorDir.'/composer/include_paths.php'); @@ -651,6 +654,7 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $notAutoloadPackage, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_static.php'); $this->assertFileNotExists($this->vendorDir.'/composer/autoload_files.php'); $this->assertFileNotExists($this->vendorDir.'/composer/include_paths.php'); } @@ -703,6 +707,7 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder'); $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_functions_by_dependency.php', $this->vendorDir . '/autoload.php'); $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_files_by_dependency.php', $this->vendorDir . '/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__ . '/Fixtures/autoload_static_files_by_dependency.php', $this->vendorDir . '/composer/autoload_static.php'); require $this->vendorDir . '/autoload.php'; @@ -966,6 +971,7 @@ EOF; $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_static_include_path.php', $this->vendorDir.'/composer/autoload_static.php'); } public function testVendorDirExcludedFromWorkingDir() diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index 7c7b6994a..7f274d55e 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -23,24 +23,34 @@ class ComposerAutoloaderInitFilesAutoloadOrder self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoloadOrder', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoloadOrder::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->register(true); - $includeFiles = require __DIR__ . '/autoload_files.php'; + if (PHP_VERSION_ID >= 50600) { + $includeFiles = Composer\Autoload\ComposerStaticInitFilesAutoloadOrder::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach ($includeFiles as $fileIdentifier => $file) { composerRequireFilesAutoloadOrder($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index e7c22c88d..cb259167a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -23,24 +23,34 @@ class ComposerAutoloaderInitFilesAutoload self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->register(true); - $includeFiles = require __DIR__ . '/autoload_files.php'; + if (PHP_VERSION_ID >= 50600) { + $includeFiles = Composer\Autoload\ComposerStaticInitFilesAutoload::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach ($includeFiles as $fileIdentifier => $file) { composerRequireFilesAutoload($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php index 75bc332af..40da00394 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php @@ -27,24 +27,34 @@ class ComposerAutoloaderInitFilesAutoload array_push($includePaths, get_include_path()); set_include_path(join(PATH_SEPARATOR, $includePaths)); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->register(true); - $includeFiles = require __DIR__ . '/autoload_files.php'; + if (PHP_VERSION_ID >= 50600) { + $includeFiles = Composer\Autoload\ComposerStaticInitFilesAutoload::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach ($includeFiles as $fileIdentifier => $file) { composerRequireFilesAutoload($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php index 5ba75c7fa..cd1d3f66b 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php @@ -23,19 +23,25 @@ class ComposerAutoloaderInitFilesAutoload self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitFilesAutoload::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->register(true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php index 9450ffa6c..e9dbd8b3e 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_include_path.php @@ -23,19 +23,25 @@ class ComposerAutoloaderInitIncludePath self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitIncludePath', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitIncludePath::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->setUseIncludePath(true); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index 1058b7e91..1694d26f1 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -23,26 +23,36 @@ class ComposerAutoloaderInitTargetDir self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInitTargetDir', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } + if (PHP_VERSION_ID >= 50600) { + require_once __DIR__ . '/autoload_static.php'; - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } + \call_user_func(\Composer\Autoload\ComposerStaticInitTargetDir::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } spl_autoload_register(array('ComposerAutoloaderInitTargetDir', 'autoload'), true, true); $loader->register(true); - $includeFiles = require __DIR__ . '/autoload_files.php'; + if (PHP_VERSION_ID >= 50600) { + $includeFiles = Composer\Autoload\ComposerStaticInitTargetDir::$files; + } else { + $includeFiles = require __DIR__ . '/autoload_files.php'; + } foreach ($includeFiles as $fileIdentifier => $file) { composerRequireTargetDir($fileIdentifier, $file); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_static_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_static_files_by_dependency.php new file mode 100644 index 000000000..ba1f9238a --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_static_files_by_dependency.php @@ -0,0 +1,24 @@ + __DIR__ . '/..' . '/c/lorem/testC.php', + '61e6098c8cafe404d6cf19e59fc2b788' => __DIR__ . '/..' . '/d/d/testD.php', + '8bceec6fdc149a1a6acbf7ad3cfed51c' => __DIR__ . '/..' . '/z/foo/testA.php', + 'c5466e580c6c2403f225c43b6a21a96f' => __DIR__ . '/..' . '/b/bar/testB.php', + '69dfc37c40a853a7cbac6c9d2367c5f4' => __DIR__ . '/..' . '/e/e/testE.php', + '334307692417e52db5a08c3271700a7e' => __DIR__ . '/../..' . '/root2.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + + }, null, ClassLoader::class); + } +} diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions.php new file mode 100644 index 000000000..dfe3c5bcc --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions.php @@ -0,0 +1,23 @@ + __DIR__ . '/..' . '/a/a/test.php', + 'e56cac94f86c787e1efd645809df361d' => __DIR__ . '/..' . '/b/b/test2.php', + 'df8470dfa2ebd6b31da05b60fb4ec29a' => __DIR__ . '/..' . '/c/c/foo/bar/test3.php', + '68f1e24e6cd39de885cb5a47678e6518' => __DIR__ . '/..' . '/c/c/foo/bar/test4.php', + '61b776fd0ee84fb7d7d958ae46118ded' => __DIR__ . '/../..' . '/root.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + + }, null, ClassLoader::class); + } +} diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_include_paths.php new file mode 100644 index 000000000..dfe3c5bcc --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_include_paths.php @@ -0,0 +1,23 @@ + __DIR__ . '/..' . '/a/a/test.php', + 'e56cac94f86c787e1efd645809df361d' => __DIR__ . '/..' . '/b/b/test2.php', + 'df8470dfa2ebd6b31da05b60fb4ec29a' => __DIR__ . '/..' . '/c/c/foo/bar/test3.php', + '68f1e24e6cd39de885cb5a47678e6518' => __DIR__ . '/..' . '/c/c/foo/bar/test4.php', + '61b776fd0ee84fb7d7d958ae46118ded' => __DIR__ . '/../..' . '/root.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + + }, null, ClassLoader::class); + } +} diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_removed_include_paths_and_autolad_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_removed_include_paths_and_autolad_files.php new file mode 100644 index 000000000..11897e11a --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_static_functions_with_removed_include_paths_and_autolad_files.php @@ -0,0 +1,15 @@ + + array ( + 'Main\\Foo' => + array ( + 0 => __DIR__ . '/../..' . '/', + ), + 'Main\\Bar' => + array ( + 0 => __DIR__ . '/../..' . '/', + ), + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixesPsr0 = ComposerStaticInitIncludePath::$prefixesPsr0; + + }, null, ClassLoader::class); + } +} diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_static_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_static_target_dir.php new file mode 100644 index 000000000..114b5a98a --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_static_target_dir.php @@ -0,0 +1,41 @@ + __DIR__ . '/../..' . '/foo.php', + 'f558c96fbd0535aaa98981fa59ff7594' => __DIR__ . '/../..' . '/bar.php', + ); + + public static $prefixesPsr0 = array ( + 'M' => + array ( + 'Main\\Foo' => + array ( + 0 => __DIR__ . '/../..' . '/', + ), + 'Main\\Bar' => + array ( + 0 => __DIR__ . '/../..' . '/', + ), + ), + ); + + public static $classMap = array ( + 'ClassMapBar' => __DIR__ . '/../..' . '/lib/rootbar.php', + 'ClassMapFoo' => __DIR__ . '/../..' . '/src/rootfoo.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixesPsr0 = ComposerStaticInitTargetDir::$prefixesPsr0; + $loader->classMap = ComposerStaticInitTargetDir::$classMap; + + }, null, ClassLoader::class); + } +}