1
0
Fork 0

Merge remote-tracking branch 'jeskew/feature/require_files_but_once'

pull/4623/head
Jordi Boggiano 2015-11-21 17:31:05 +00:00
commit 9710b26d3f
10 changed files with 84 additions and 34 deletions

View File

@ -475,8 +475,9 @@ EOF;
protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode) protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode)
{ {
$filesCode = ''; $filesCode = '';
foreach ($files as $functionFile) { foreach ($files as $fileIdentifier => $functionFile) {
$filesCode .= ' '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).",\n"; $filesCode .= ' ' . $fileIdentifier . ' => '
. $this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile) . ",\n";
} }
if (!$filesCode) { if (!$filesCode) {
@ -649,8 +650,8 @@ REGISTER_LOADER;
if ($useIncludeFiles) { if ($useIncludeFiles) {
$file .= <<<INCLUDE_FILES $file .= <<<INCLUDE_FILES
\$includeFiles = require __DIR__ . '/autoload_files.php'; \$includeFiles = require __DIR__ . '/autoload_files.php';
foreach (\$includeFiles as \$file) { foreach (\$includeFiles as \$fileIdentifier => \$file) {
composerRequire$suffix(\$file); composerRequire$suffix(\$fileIdentifier, \$file);
} }
@ -668,9 +669,17 @@ METHOD_FOOTER;
return $file . <<<FOOTER return $file . <<<FOOTER
} }
function composerRequire$suffix(\$file) function composerRequire$suffix(\$fileIdentifier, \$file)
{ {
if (empty(\$GLOBALS['composerRequiredFiles'])) {
\$GLOBALS['composerRequiredFiles'] = array();
}
if (empty(\$GLOBALS['composerRequiredFiles'][\$fileIdentifier])) {
require \$file; require \$file;
\$GLOBALS['composerRequiredFiles'][\$fileIdentifier] = true;
}
} }
FOOTER; FOOTER;
@ -742,7 +751,11 @@ FOOTER;
$relativePath = empty($installPath) ? (empty($path) ? '.' : $path) : $installPath.'/'.$path; $relativePath = empty($installPath) ? (empty($path) ? '.' : $path) : $installPath.'/'.$path;
if ($type === 'files' || $type === 'classmap') { if ($type === 'files') {
$autoloads[var_export($this->getFileIdentifier($relativePath), true)]
= $relativePath;
continue;
} elseif ($type === 'classmap') {
$autoloads[] = $relativePath; $autoloads[] = $relativePath;
continue; continue;
} }
@ -755,6 +768,11 @@ FOOTER;
return $autoloads; return $autoloads;
} }
protected function getFileIdentifier($path)
{
return md5_file($path);
}
/** /**
* Sorts packages by dependency weight * Sorts packages by dependency weight
* *

View File

@ -1069,8 +1069,8 @@ EOF;
$this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php')); $this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php'));
$this->assertEquals($expectedPsr4, file_get_contents($vendorDir.'/composer/autoload_psr4.php')); $this->assertEquals($expectedPsr4, file_get_contents($vendorDir.'/composer/autoload_psr4.php'));
$this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php')); $this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
$this->assertContains("\n \$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); $this->assertContains("\$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
$this->assertContains("\n \$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); $this->assertContains("\$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
} }
public function testUpLevelRelativePaths() public function testUpLevelRelativePaths()
@ -1147,7 +1147,7 @@ EOF;
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php')); $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
$this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php')); $this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php')); $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
$this->assertContains("\n \$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php')); $this->assertContains("\$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
} }
public function testEmptyPaths() public function testEmptyPaths()

View File

@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
$baseDir . '/foo.php', '25b429360a61ca2629fdf9a4f484981c' => $baseDir . '/foo.php',
$baseDir . '/bar.php', '524f65941cc9a0fa65ff0ec097ccde8a' => $baseDir . '/bar.php',
); );

View File

@ -6,5 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
$baseDir . '/devfiles/foo.php', 'fc1e99cd93a6aa58e3b1565e688bcd87' => $baseDir . '/devfiles/foo.php',
); );

View File

@ -6,9 +6,9 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
$vendorDir . '/a/a/test.php', 'b18a3c4a24b1dc69fdd96098e5c28e01' => $vendorDir . '/a/a/test.php',
$vendorDir . '/b/b/test2.php', '93797e35718fdafb825b1fe25c08a92c' => $vendorDir . '/b/b/test2.php',
$vendorDir . '/c/c/foo/bar/test3.php', 'a57008eef928ced7c299bfea724d8441' => $vendorDir . '/c/c/foo/bar/test3.php',
$vendorDir . '/c/c/foo/bar/test4.php', '32e13a06a803ac6553a93454bcd3d2da' => $vendorDir . '/c/c/foo/bar/test4.php',
$baseDir . '/root.php', '504bb142db8acef729eeeb06b0aedec5' => $baseDir . '/root.php',
); );

View File

@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
$baseDir . '/foo.php', '25b429360a61ca2629fdf9a4f484981c' => $baseDir . '/foo.php',
$baseDir . '/bar.php', '524f65941cc9a0fa65ff0ec097ccde8a' => $baseDir . '/bar.php',
); );

View File

@ -41,15 +41,23 @@ class ComposerAutoloaderInitFilesAutoloadOrder
$loader->register(true); $loader->register(true);
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireFilesAutoloadOrder($file); composerRequireFilesAutoloadOrder($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequireFilesAutoloadOrder($file) function composerRequireFilesAutoloadOrder($fileIdentifier, $file)
{ {
require $file; if (empty($GLOBALS['composerRequiredFiles'])) {
$GLOBALS['composerRequiredFiles'] = array();
}
if (empty($GLOBALS['composerRequiredFiles'][$fileIdentifier])) {
require $file;
$GLOBALS['composerRequiredFiles'][$fileIdentifier] = true;
}
} }

View File

@ -41,15 +41,23 @@ class ComposerAutoloaderInitFilesAutoload
$loader->register(true); $loader->register(true);
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireFilesAutoload($file); composerRequireFilesAutoload($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequireFilesAutoload($file) function composerRequireFilesAutoload($fileIdentifier, $file)
{ {
require $file; if (empty($GLOBALS['composerRequiredFiles'])) {
$GLOBALS['composerRequiredFiles'] = array();
}
if (empty($GLOBALS['composerRequiredFiles'][$fileIdentifier])) {
require $file;
$GLOBALS['composerRequiredFiles'][$fileIdentifier] = true;
}
} }

View File

@ -65,7 +65,15 @@ class ComposerAutoloaderInitIncludePath
} }
} }
function composerRequireIncludePath($file) function composerRequireIncludePath($fileIdentifier, $file)
{ {
require $file; if (empty($GLOBALS['composerRequiredFiles'])) {
$GLOBALS['composerRequiredFiles'] = array();
}
if (empty($GLOBALS['composerRequiredFiles'][$fileIdentifier])) {
require $file;
$GLOBALS['composerRequiredFiles'][$fileIdentifier] = true;
}
} }

View File

@ -43,8 +43,8 @@ class ComposerAutoloaderInitTargetDir
$loader->register(true); $loader->register(true);
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireTargetDir($file); composerRequireTargetDir($fileIdentifier, $file);
} }
return $loader; return $loader;
@ -69,7 +69,15 @@ class ComposerAutoloaderInitTargetDir
} }
} }
function composerRequireTargetDir($file) function composerRequireTargetDir($fileIdentifier, $file)
{ {
require $file; if (empty($GLOBALS['composerRequiredFiles'])) {
$GLOBALS['composerRequiredFiles'] = array();
}
if (empty($GLOBALS['composerRequiredFiles'][$fileIdentifier])) {
require $file;
$GLOBALS['composerRequiredFiles'][$fileIdentifier] = true;
}
} }