|
|
|
@ -69,9 +69,23 @@ return array(
|
|
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
|
|
|
|
|
$psr4File = <<<EOF
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
|
|
|
|
|
\$vendorDir = $vendorPathCode52;
|
|
|
|
|
\$baseDir = $appBaseDirCode;
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
|
|
|
|
|
// Collect information from all packages.
|
|
|
|
|
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
|
|
|
|
|
$autoloads = $this->parseAutoloads($packageMap, $mainPackage);
|
|
|
|
|
|
|
|
|
|
// Process the 'psr-0' base directories.
|
|
|
|
|
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
|
|
|
|
$exportedPaths = array();
|
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
@ -83,6 +97,21 @@ EOF;
|
|
|
|
|
}
|
|
|
|
|
$namespacesFile .= ");\n";
|
|
|
|
|
|
|
|
|
|
// Process the 'psr-4' base directories.
|
|
|
|
|
foreach ($autoloads['psr-4'] as $namespace => $paths) {
|
|
|
|
|
if ('\\' !== $namespace[strlen($namespace) - 1]) {
|
|
|
|
|
throw new \Exception("PSR-4 namespaces must end with a namespace separator. '$namespace' does not.");
|
|
|
|
|
}
|
|
|
|
|
$exportedPaths = array();
|
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
|
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
|
|
|
|
|
}
|
|
|
|
|
$exportedPrefix = var_export($namespace, true);
|
|
|
|
|
$psr4File .= " $exportedPrefix => ";
|
|
|
|
|
$psr4File .= "array(".implode(', ', $exportedPaths)."),\n";
|
|
|
|
|
}
|
|
|
|
|
$psr4File .= ");\n";
|
|
|
|
|
|
|
|
|
|
$classmapFile = <<<EOF
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
@ -131,6 +160,8 @@ EOF;
|
|
|
|
|
// flatten array
|
|
|
|
|
$classMap = array();
|
|
|
|
|
if ($scanPsr0Packages) {
|
|
|
|
|
// Scan the PSR-0 directories for class files, and add them to the
|
|
|
|
|
// class map.
|
|
|
|
|
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
|
|
|
|
foreach ($paths as $dir) {
|
|
|
|
|
$dir = $filesystem->normalizePath($filesystem->isAbsolutePath($dir) ? $dir : $basePath.'/'.$dir);
|
|
|
|
@ -152,6 +183,29 @@ EOF;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Scan the PSR-4 directories for class files, and add them to the
|
|
|
|
|
// class map.
|
|
|
|
|
foreach ($autoloads['psr-4'] as $namespace => $paths) {
|
|
|
|
|
foreach ($paths as $dir) {
|
|
|
|
|
$dir = $filesystem->normalizePath($filesystem->isAbsolutePath($dir) ? $dir : $basePath.'/'.$dir);
|
|
|
|
|
if (!is_dir($dir)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$whitelist = sprintf(
|
|
|
|
|
'{%s/%s.+(?<!(?<!/)Test\.php)$}',
|
|
|
|
|
preg_quote($dir),
|
|
|
|
|
strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : ''
|
|
|
|
|
);
|
|
|
|
|
foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
|
|
|
|
|
if ('' === $namespace || 0 === strpos($class, $namespace)) {
|
|
|
|
|
if (!isset($classMap[$class])) {
|
|
|
|
|
$path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
|
|
|
|
|
$classMap[$class] = $path.",\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
|
|
|
@ -173,6 +227,7 @@ EOF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
|
|
|
|
file_put_contents($targetDir.'/autoload_psr4.php', $psr4File);
|
|
|
|
|
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
|
|
|
|
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
|
|
|
|
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
|
|
|
@ -181,7 +236,7 @@ EOF;
|
|
|
|
|
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
|
|
|
|
|
}
|
|
|
|
|
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
|
|
|
|
|
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader));
|
|
|
|
|
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader));
|
|
|
|
|
|
|
|
|
|
// use stream_copy_to_stream instead of copy
|
|
|
|
|
// to work around https://bugs.php.net/bug.php?id=64634
|
|
|
|
@ -229,12 +284,14 @@ EOF;
|
|
|
|
|
array_unshift($packageMap, $mainPackageMap);
|
|
|
|
|
|
|
|
|
|
$psr0 = $this->parseAutoloadsType($packageMap, 'psr-0', $mainPackage);
|
|
|
|
|
$psr4 = $this->parseAutoloadsType($packageMap, 'psr-4', $mainPackage);
|
|
|
|
|
$classmap = $this->parseAutoloadsType($sortedPackageMap, 'classmap', $mainPackage);
|
|
|
|
|
$files = $this->parseAutoloadsType($sortedPackageMap, 'files', $mainPackage);
|
|
|
|
|
|
|
|
|
|
krsort($psr0);
|
|
|
|
|
krsort($psr4);
|
|
|
|
|
|
|
|
|
|
return array('psr-0' => $psr0, 'classmap' => $classmap, 'files' => $files);
|
|
|
|
|
return array('psr-0' => $psr0, 'psr-4' => $psr4, 'classmap' => $classmap, 'files' => $files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -366,7 +423,7 @@ return ComposerAutoloaderInit$suffix::getLoader();
|
|
|
|
|
AUTOLOAD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getAutoloadRealFile($usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)
|
|
|
|
|
protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader)
|
|
|
|
|
{
|
|
|
|
|
// TODO the class ComposerAutoloaderInit should be revert to a closure
|
|
|
|
|
// when APC has been fixed:
|
|
|
|
@ -417,8 +474,7 @@ HEADER;
|
|
|
|
|
INCLUDE_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($usePSR0) {
|
|
|
|
|
$file .= <<<'PSR0'
|
|
|
|
|
$file .= <<<'PSR0'
|
|
|
|
|
$map = require __DIR__ . '/autoload_namespaces.php';
|
|
|
|
|
foreach ($map as $namespace => $path) {
|
|
|
|
|
$loader->set($namespace, $path);
|
|
|
|
@ -426,8 +482,16 @@ INCLUDE_PATH;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PSR0;
|
|
|
|
|
|
|
|
|
|
$file .= <<<'PSR4'
|
|
|
|
|
$map = require __DIR__ . '/autoload_psr4.php';
|
|
|
|
|
foreach ($map as $namespace => $path) {
|
|
|
|
|
$loader->setPsr4($namespace, $path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PSR4;
|
|
|
|
|
|
|
|
|
|
if ($useClassMap) {
|
|
|
|
|
$file .= <<<'CLASSMAP'
|
|
|
|
|
$classMap = require __DIR__ . '/autoload_classmap.php';
|
|
|
|
|