Factor the filesCode generation into a separate method.
parent
f98a8f472e
commit
8e9bdfb4da
|
@ -167,12 +167,6 @@ EOF;
|
||||||
}
|
}
|
||||||
$classmapFile .= ");\n";
|
$classmapFile .= ");\n";
|
||||||
|
|
||||||
$filesCode = "";
|
|
||||||
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
|
||||||
foreach ($autoloads['files'] as $functionFile) {
|
|
||||||
$filesCode .= 'require '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).";\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$suffix) {
|
if (!$suffix) {
|
||||||
$suffix = md5(uniqid('', true));
|
$suffix = md5(uniqid('', true));
|
||||||
}
|
}
|
||||||
|
@ -182,13 +176,11 @@ EOF;
|
||||||
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
||||||
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
||||||
}
|
}
|
||||||
if ($filesCode) {
|
if ($includeFilesFile = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
||||||
$filesCode = "<?php\n\n".rtrim($filesCode)."\n";
|
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
|
||||||
file_put_contents($targetDir.'/autoload_files.php', $filesCode);
|
|
||||||
$filesCode = " require __DIR__ . '/autoload_files.php';";
|
|
||||||
}
|
}
|
||||||
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
|
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
|
||||||
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath));
|
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath));
|
||||||
|
|
||||||
// use stream_copy_to_stream instead of copy
|
// use stream_copy_to_stream instead of copy
|
||||||
// to work around https://bugs.php.net/bug.php?id=64634
|
// to work around https://bugs.php.net/bug.php?id=64634
|
||||||
|
@ -303,6 +295,31 @@ EOF;
|
||||||
return $includePathsFile . ");\n";
|
return $includePathsFile . ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
|
||||||
|
{
|
||||||
|
$filesCode = '';
|
||||||
|
$files = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($files));
|
||||||
|
foreach ($files as $functionFile) {
|
||||||
|
$filesCode .= 'require '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).";\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$filesCode) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
$filesCode = rtrim($filesCode);
|
||||||
|
|
||||||
|
return <<<EOF
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php generated by Composer
|
||||||
|
|
||||||
|
\$vendorDir = $vendorPathCode;
|
||||||
|
\$baseDir = $appBaseDirCode;
|
||||||
|
|
||||||
|
$filesCode
|
||||||
|
EOF;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getPathCode(Filesystem $filesystem, $basePath, $vendorPath, $path)
|
protected function getPathCode(Filesystem $filesystem, $basePath, $vendorPath, $path)
|
||||||
{
|
{
|
||||||
if (!$filesystem->isAbsolutePath($path)) {
|
if (!$filesystem->isAbsolutePath($path)) {
|
||||||
|
@ -343,7 +360,7 @@ return ComposerAutoloaderInit$suffix::getLoader();
|
||||||
AUTOLOAD;
|
AUTOLOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath)
|
protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath)
|
||||||
{
|
{
|
||||||
// TODO the class ComposerAutoloaderInit should be revert to a closure
|
// TODO the class ComposerAutoloaderInit should be revert to a closure
|
||||||
// when APC has been fixed:
|
// when APC has been fixed:
|
||||||
|
@ -352,10 +369,6 @@ AUTOLOAD;
|
||||||
// - https://bugs.php.net/bug.php?id=61576
|
// - https://bugs.php.net/bug.php?id=61576
|
||||||
// - https://bugs.php.net/bug.php?id=59298
|
// - https://bugs.php.net/bug.php?id=59298
|
||||||
|
|
||||||
if ($filesCode) {
|
|
||||||
$filesCode = "\n\n".rtrim($filesCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$file = <<<HEADER
|
$file = <<<HEADER
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -436,9 +449,22 @@ REGISTER_AUTOLOAD;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$file .= <<<METHOD_FOOTER
|
$file .= <<<REGISTER_LOADER
|
||||||
\$loader->register(true);{$filesCode}
|
\$loader->register(true);
|
||||||
|
|
||||||
|
|
||||||
|
REGISTER_LOADER;
|
||||||
|
|
||||||
|
if ($useIncludeFiles) {
|
||||||
|
$file .= <<<INCLUDE_FILES
|
||||||
|
require __DIR__ . '/autoload_files.php';
|
||||||
|
|
||||||
|
|
||||||
|
INCLUDE_FILES;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$file .= <<<METHOD_FOOTER
|
||||||
return \$loader;
|
return \$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
require $baseDir . '/foo.php';
|
require $baseDir . '/foo.php';
|
||||||
require $baseDir . '/bar.php';
|
require $baseDir . '/bar.php';
|
|
@ -1,8 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
require $vendorDir . '/c/lorem/testC.php';
|
require $vendorDir . '/c/lorem/testC.php';
|
||||||
require $vendorDir . '/z/foo/testA.php';
|
require $vendorDir . '/z/foo/testA.php';
|
||||||
require $vendorDir . '/d/d/testD.php';
|
require $vendorDir . '/d/d/testD.php';
|
||||||
require $vendorDir . '/b/bar/testB.php';
|
require $vendorDir . '/b/bar/testB.php';
|
||||||
require $vendorDir . '/e/e/testE.php';
|
require $vendorDir . '/e/e/testE.php';
|
||||||
require $baseDir . '/root.php';
|
require $baseDir . '/root.php';
|
|
@ -1,7 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
require $vendorDir . '/a/a/test.php';
|
require $vendorDir . '/a/a/test.php';
|
||||||
require $vendorDir . '/b/b/test2.php';
|
require $vendorDir . '/b/b/test2.php';
|
||||||
require $vendorDir . '/c/c/foo/bar/test3.php';
|
require $vendorDir . '/c/c/foo/bar/test3.php';
|
||||||
require $baseDir . '/root.php';
|
require $baseDir . '/root.php';
|
||||||
require $vendorDir . '/c/c/foo/bar/test4.php';
|
require $vendorDir . '/c/c/foo/bar/test4.php';
|
|
@ -1,4 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// autoload_files.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
require $baseDir . '/foo.php';
|
require $baseDir . '/foo.php';
|
||||||
require $baseDir . '/bar.php';
|
require $baseDir . '/bar.php';
|
Loading…
Reference in New Issue