|
@@ -34,8 +34,8 @@ class AutoloadGenerator
|
|
|
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true);
|
|
|
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
|
|
|
|
|
- $appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
|
|
- $appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
|
|
|
+ $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
|
|
+ $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
|
|
|
|
|
|
$namespacesFile = <<<EOF
|
|
|
<?php
|
|
@@ -43,7 +43,7 @@ class AutoloadGenerator
|
|
|
// autoload_namespace.php generated by Composer
|
|
|
|
|
|
\$vendorDir = $vendorDirCode;
|
|
|
-\$baseDir = $appBaseDir;
|
|
|
+\$baseDir = $appBaseDirCode;
|
|
|
|
|
|
return array(
|
|
|
|
|
@@ -55,22 +55,7 @@ EOF;
|
|
|
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
|
|
$exportedPaths = array();
|
|
|
foreach ($paths as $path) {
|
|
|
- $path = strtr($path, '\\', '/');
|
|
|
- $baseDir = '';
|
|
|
- if (!$filesystem->isAbsolutePath($path)) {
|
|
|
- if (strpos($path, $relVendorPath) === 0) {
|
|
|
- // path starts with vendor dir
|
|
|
- $path = substr($path, strlen($relVendorPath));
|
|
|
- $baseDir = '$vendorDir . ';
|
|
|
- } else {
|
|
|
- $path = '/'.$path;
|
|
|
- $baseDir = '$baseDir . ';
|
|
|
- }
|
|
|
- } elseif (strpos($path, $vendorPath) === 0) {
|
|
|
- $path = substr($path, strlen($vendorPath));
|
|
|
- $baseDir = '$vendorDir . ';
|
|
|
- }
|
|
|
- $exportedPaths[] = $baseDir.var_export($path, true);
|
|
|
+ $exportedPaths[] = $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path);
|
|
|
}
|
|
|
$exportedPrefix = var_export($namespace, true);
|
|
|
$namespacesFile .= " $exportedPrefix => ";
|
|
@@ -88,7 +73,7 @@ EOF;
|
|
|
// autoload_classmap.php generated by Composer
|
|
|
|
|
|
\$vendorDir = $vendorDirCode;
|
|
|
-\$baseDir = $appBaseDir;
|
|
|
+\$baseDir = $appBaseDirCode;
|
|
|
|
|
|
return array(
|
|
|
|
|
@@ -106,7 +91,7 @@ EOF;
|
|
|
|
|
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
|
|
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
|
|
- if ($includePathFile = $this->getIncludePathsFile($packageMap)) {
|
|
|
+ if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorDirCode, $appBaseDirCode)) {
|
|
|
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
|
|
}
|
|
|
file_put_contents($targetDir.'/autoload.php', $this->getAutoloadFile(true, true, (Boolean) $includePathFile));
|
|
@@ -186,7 +171,7 @@ EOF;
|
|
|
return $loader;
|
|
|
}
|
|
|
|
|
|
- protected function getIncludePathsFile(array $packageMap)
|
|
|
+ protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $relVendorPath, $vendorPath, $vendorDirCode, $appBaseDirCode)
|
|
|
{
|
|
|
$includePaths = array();
|
|
|
|
|
@@ -198,6 +183,7 @@ EOF;
|
|
|
}
|
|
|
|
|
|
foreach ($package->getIncludePaths() as $includePath) {
|
|
|
+ $includePath = trim($includePath, '/');
|
|
|
$includePaths[] = empty($installPath) ? $includePath : $installPath.'/'.$includePath;
|
|
|
}
|
|
|
}
|
|
@@ -206,9 +192,43 @@ EOF;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- return sprintf(
|
|
|
- "<?php\nreturn %s;\n", var_export($includePaths, true)
|
|
|
- );
|
|
|
+ $includePathsFile = <<<EOF
|
|
|
+<?php
|
|
|
+
|
|
|
+// include_paths.php generated by Composer
|
|
|
+
|
|
|
+\$vendorDir = $vendorDirCode;
|
|
|
+\$baseDir = $appBaseDirCode;
|
|
|
+
|
|
|
+return array(
|
|
|
+
|
|
|
+EOF;
|
|
|
+
|
|
|
+ foreach ($includePaths as $path) {
|
|
|
+ $includePathsFile .= " " . $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path) . ",\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $includePathsFile . ");\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getPathCode(Filesystem $filesystem, $relVendorPath, $vendorPath, $path)
|
|
|
+ {
|
|
|
+ $path = strtr($path, '\\', '/');
|
|
|
+ $baseDir = '';
|
|
|
+ if (!$filesystem->isAbsolutePath($path)) {
|
|
|
+ if (strpos($path, $relVendorPath) === 0) {
|
|
|
+ // path starts with vendor dir
|
|
|
+ $path = substr($path, strlen($relVendorPath));
|
|
|
+ $baseDir = '$vendorDir . ';
|
|
|
+ } else {
|
|
|
+ $path = '/'.$path;
|
|
|
+ $baseDir = '$baseDir . ';
|
|
|
+ }
|
|
|
+ } elseif (strpos($path, $vendorPath) === 0) {
|
|
|
+ $path = substr($path, strlen($vendorPath));
|
|
|
+ $baseDir = '$vendorDir . ';
|
|
|
+ }
|
|
|
+ return $baseDir.var_export($path, true);
|
|
|
}
|
|
|
|
|
|
protected function getAutoloadFile($usePSR0, $useClassMap, $useIncludePath)
|