|
@@ -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 .= <<<STATIC_INIT
|
|
|
+ if (PHP_VERSION_ID >= 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 .= <<<INCLUDE_FILES
|
|
|
- \$includeFiles = require __DIR__ . '/autoload_files.php';
|
|
|
+ if (PHP_VERSION_ID >= 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 = <<<HEADER
|
|
|
+<?php
|
|
|
+
|
|
|
+// autoload_static.php @generated by Composer
|
|
|
+
|
|
|
+namespace Composer\Autoload;
|
|
|
+
|
|
|
+class ComposerStaticInit$suffix
|
|
|
+{
|
|
|
+
|
|
|
+HEADER;
|
|
|
+
|
|
|
+ $loader = new ClassLoader();
|
|
|
+
|
|
|
+ $map = require $targetDir . '/autoload_namespaces.php';
|
|
|
+ foreach ($map as $namespace => $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 . <<<INITIALIZER
|
|
|
+ public static function getInitializer(ClassLoader \$loader)
|
|
|
+ {
|
|
|
+ return \Closure::bind(function () use (\$loader) {
|
|
|
+$initializer
|
|
|
+ }, null, ClassLoader::class);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+INITIALIZER;
|
|
|
+ }
|
|
|
+
|
|
|
protected function parseAutoloadsType(array $packageMap, $type, PackageInterface $mainPackage)
|
|
|
{
|
|
|
$autoloads = array();
|