From 40aca80bd9eddb6219f8c5cc05193b26f52e27ee Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 12 Apr 2016 09:32:54 +0200 Subject: [PATCH] Workaround https://bugs.php.net/68057 --- src/Composer/Autoload/AutoloadGenerator.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 77a2a02fc..5664c93a0 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -283,9 +283,9 @@ EOF; } elseif (file_exists($includeFilesFilePath)) { unlink($includeFilesFilePath); } + file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion)); 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)); + file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion)); $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE'); @@ -538,7 +538,7 @@ return ComposerAutoloaderInit$suffix::getLoader(); AUTOLOAD; } - protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader) + protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion = 70000) { $file = <<
= 50600) { + if (PHP_VERSION_ID >= $staticPhpVersion) { require_once __DIR__ . '/autoload_static.php'; call_user_func(\Composer\Autoload\ComposerStaticInit$suffix::getInitializer(\$loader)); @@ -646,7 +646,7 @@ REGISTER_LOADER; if ($useIncludeFiles) { $file .= <<= 50600) { + if (PHP_VERSION_ID >= $staticPhpVersion) { \$includeFiles = Composer\Autoload\ComposerStaticInit$suffix::\$files; } else { \$includeFiles = require __DIR__ . '/autoload_files.php'; @@ -689,8 +689,10 @@ FOOTER; FOOTER; } - protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath) + protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath, &$staticPhpVersion) { + $staticPhpVersion = 50600; + $file = <<
$value) { + if (count($value) > 32767) { + // Static arrays are limited to 32767 values on PHP 5.6 + // See https://bugs.php.net/68057 + $staticPhpVersion = 70000; + } $value = var_export($value, true); $value = str_replace($absoluteVendorPathCode, $vendorPathCode, $value); $value = str_replace($absoluteAppBaseDirCode, $appBaseDirCode, $value);