1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 00:53:06 +00:00

Add Files Autoloading key. This is a necessary feature to allow purely or partly functional libraries to be "autoloadable" by composer by calling require_once on every file in the "autoload"."files" list.

This commit is contained in:
Benjamin Eberlei 2012-06-02 18:18:33 +02:00
parent 639aba6f99
commit 5c5e962b5a
5 changed files with 62 additions and 4 deletions

View file

@ -121,12 +121,19 @@ EOF;
}
$classmapFile .= ");\n";
$filesCode = "";
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
foreach ($autoloads['files'] as $functionFile) {
$filesCode .= 'require "' . $filesystem->findShortestPath(getcwd(), $functionFile) .'";' . "\n";
}
$filesCode = rtrim($filesCode);
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)) {
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
}
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (Boolean) $includePathFile, $targetDirLoader));
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, true, true, (Boolean) $includePathFile, $targetDirLoader, $filesCode));
copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
// TODO BC feature, remove after June 15th
@ -173,7 +180,7 @@ EOF;
*/
public function parseAutoloads(array $packageMap)
{
$autoloads = array('classmap' => array(), 'psr-0' => array());
$autoloads = array('classmap' => array(), 'psr-0' => array(), 'files' => array());
foreach ($packageMap as $item) {
list($package, $installPath) = $item;
@ -281,7 +288,7 @@ EOF;
return $baseDir.var_export($path, true);
}
protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader)
protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode)
{
$file = <<<HEADER
<?php
@ -291,6 +298,8 @@ if (!class_exists('Composer\\\\Autoload\\\\ClassLoader', false)) {
require $vendorPathToTargetDirCode . '/ClassLoader.php';
}
$filesCode
return call_user_func(function() {
\$loader = new \\Composer\\Autoload\\ClassLoader();
\$composerDir = $vendorPathToTargetDirCode;