Cosmetic fixes to autoload generation
parent
e316cb452b
commit
1df9c62583
|
@ -98,10 +98,10 @@ EOF;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
\$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
\$path = \$dir . implode('/', array_slice(explode('\\\\', \$class), $levels)).'.php';
|
||||||
if (!stream_resolve_include_path(\$path)) {
|
if (!\$path = stream_resolve_include_path(\$path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
require_once \$path;
|
require \$path;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -121,12 +121,11 @@ EOF;
|
||||||
}
|
}
|
||||||
$classmapFile .= ");\n";
|
$classmapFile .= ");\n";
|
||||||
|
|
||||||
$filesCode = "";
|
$filesCode = "";
|
||||||
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
||||||
foreach ($autoloads['files'] as $functionFile) {
|
foreach ($autoloads['files'] as $functionFile) {
|
||||||
$filesCode .= 'require "' . $filesystem->findShortestPath(getcwd(), $functionFile) .'";' . "\n";
|
$filesCode .= 'require __DIR__ . '. var_export('/'.$filesystem->findShortestPath($vendorPath, $functionFile), true).";\n";
|
||||||
}
|
}
|
||||||
$filesCode = rtrim($filesCode);
|
|
||||||
|
|
||||||
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
||||||
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
||||||
|
@ -290,6 +289,10 @@ EOF;
|
||||||
|
|
||||||
protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode)
|
protected function getAutoloadFile($vendorPathToTargetDirCode, $usePSR0, $useClassMap, $useIncludePath, $targetDirLoader, $filesCode)
|
||||||
{
|
{
|
||||||
|
if ($filesCode) {
|
||||||
|
$filesCode = "\n".$filesCode;
|
||||||
|
}
|
||||||
|
|
||||||
$file = <<<HEADER
|
$file = <<<HEADER
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -297,9 +300,7 @@ EOF;
|
||||||
if (!class_exists('Composer\\\\Autoload\\\\ClassLoader', false)) {
|
if (!class_exists('Composer\\\\Autoload\\\\ClassLoader', false)) {
|
||||||
require $vendorPathToTargetDirCode . '/ClassLoader.php';
|
require $vendorPathToTargetDirCode . '/ClassLoader.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$filesCode
|
$filesCode
|
||||||
|
|
||||||
return call_user_func(function() {
|
return call_user_func(function() {
|
||||||
\$loader = new \\Composer\\Autoload\\ClassLoader();
|
\$loader = new \\Composer\\Autoload\\ClassLoader();
|
||||||
\$composerDir = $vendorPathToTargetDirCode;
|
\$composerDir = $vendorPathToTargetDirCode;
|
||||||
|
|
|
@ -147,7 +147,7 @@ class ClassLoader
|
||||||
public function loadClass($class)
|
public function loadClass($class)
|
||||||
{
|
{
|
||||||
if ($file = $this->findFile($class)) {
|
if ($file = $this->findFile($class)) {
|
||||||
require $file;
|
include $file;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,13 +271,9 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
|
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
|
||||||
|
|
||||||
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/composer');
|
||||||
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
|
||||||
$code = file_get_contents($this->vendorDir.'/autoload.php');
|
|
||||||
$this->assertContains('a/a/test.php', $code);
|
|
||||||
$this->assertContains('b/b/test2.php', $code);
|
|
||||||
|
|
||||||
include $this->vendorDir . '/autoload.php';
|
include $this->vendorDir . '/autoload.php';
|
||||||
|
|
||||||
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
|
||||||
$this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload.php generated by Composer
|
||||||
|
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
||||||
|
require __DIR__ . '/composer' . '/ClassLoader.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
require __DIR__ . '/a/a/test.php';
|
||||||
|
require __DIR__ . '/b/b/test2.php';
|
||||||
|
|
||||||
|
return call_user_func(function() {
|
||||||
|
$loader = new \Composer\Autoload\ClassLoader();
|
||||||
|
$composerDir = __DIR__ . '/composer';
|
||||||
|
|
||||||
|
$map = require $composerDir . '/autoload_namespaces.php';
|
||||||
|
foreach ($map as $namespace => $path) {
|
||||||
|
$loader->add($namespace, $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$classMap = require $composerDir . '/autoload_classmap.php';
|
||||||
|
if ($classMap) {
|
||||||
|
$loader->addClassMap($classMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
$loader->register();
|
||||||
|
|
||||||
|
return $loader;
|
||||||
|
});
|
|
@ -5,8 +5,6 @@ if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
|
||||||
require __DIR__ . '/composer' . '/ClassLoader.php';
|
require __DIR__ . '/composer' . '/ClassLoader.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return call_user_func(function() {
|
return call_user_func(function() {
|
||||||
$loader = new \Composer\Autoload\ClassLoader();
|
$loader = new \Composer\Autoload\ClassLoader();
|
||||||
$composerDir = __DIR__ . '/composer';
|
$composerDir = __DIR__ . '/composer';
|
||||||
|
@ -29,10 +27,10 @@ return call_user_func(function() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$path = $dir . implode('/', array_slice(explode('\\', $class), 2)).'.php';
|
$path = $dir . implode('/', array_slice(explode('\\', $class), 2)).'.php';
|
||||||
if (!stream_resolve_include_path($path)) {
|
if (!$path = stream_resolve_include_path($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
require_once $path;
|
require $path;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue