|
@@ -61,12 +61,16 @@ EOF;
|
|
|
$relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath);
|
|
|
$vendorDirCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
|
|
|
|
|
+ $appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
|
|
+ $appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
|
|
|
+
|
|
|
$namespacesFile = <<<EOF
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
\$vendorDir = $vendorDirCode;
|
|
|
+\$baseDir = $appBaseDir;
|
|
|
|
|
|
return array(
|
|
|
|
|
@@ -75,56 +79,65 @@ EOF;
|
|
|
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
|
|
|
$autoloads = $this->parseAutoloads($packageMap);
|
|
|
|
|
|
- $appBaseDir = $filesystem->findShortestPathCode($vendorPath, getcwd(), true);
|
|
|
- $appBaseDir = str_replace('__DIR__', '$vendorDir', $appBaseDir);
|
|
|
-
|
|
|
- if (isset($autoloads['psr-0'])) {
|
|
|
- foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
|
|
- $exportedPaths = array();
|
|
|
- foreach ($paths as $path) {
|
|
|
- $path = strtr($path, '\\', '/');
|
|
|
- $baseDir = '';
|
|
|
- if (!$filesystem->isAbsolutePath($path)) {
|
|
|
-
|
|
|
- if (preg_match('{^(\./?)?$}', $relVendorPath)) {
|
|
|
- $path = '/'.$path;
|
|
|
- $baseDir = '$vendorDir . ';
|
|
|
- } elseif (strpos($path, $relVendorPath) === 0) {
|
|
|
-
|
|
|
- $path = substr($path, strlen($relVendorPath));
|
|
|
- $baseDir = '$vendorDir . ';
|
|
|
- } else {
|
|
|
- $path = '/'.$path;
|
|
|
- $baseDir = $appBaseDir . ' . ';
|
|
|
- }
|
|
|
- } elseif (strpos($path, $vendorPath) === 0) {
|
|
|
- $path = substr($path, strlen($vendorPath));
|
|
|
+ foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
|
|
+ $exportedPaths = array();
|
|
|
+ foreach ($paths as $path) {
|
|
|
+ $path = strtr($path, '\\', '/');
|
|
|
+ $baseDir = '';
|
|
|
+ if (!$filesystem->isAbsolutePath($path)) {
|
|
|
+
|
|
|
+ if (preg_match('{^(\./?)?$}', $relVendorPath)) {
|
|
|
+ $path = '/'.$path;
|
|
|
+ $baseDir = '$vendorDir . ';
|
|
|
+ } elseif (strpos($path, $relVendorPath) === 0) {
|
|
|
+
|
|
|
+ $path = substr($path, strlen($relVendorPath));
|
|
|
$baseDir = '$vendorDir . ';
|
|
|
+ } else {
|
|
|
+ $path = '/'.$path;
|
|
|
+ $baseDir = '$baseDir . ';
|
|
|
}
|
|
|
- $exportedPaths[] = $baseDir.var_export($path, true);
|
|
|
- }
|
|
|
- $exportedPrefix = var_export($namespace, true);
|
|
|
- $namespacesFile .= " $exportedPrefix => ";
|
|
|
- if (count($exportedPaths) > 1) {
|
|
|
- $namespacesFile .= "array(".implode(', ',$exportedPaths)."),\n";
|
|
|
- } else {
|
|
|
- $namespacesFile .= $exportedPaths[0].",\n";
|
|
|
+ } elseif (strpos($path, $vendorPath) === 0) {
|
|
|
+ $path = substr($path, strlen($vendorPath));
|
|
|
+ $baseDir = '$vendorDir . ';
|
|
|
}
|
|
|
+ $exportedPaths[] = $baseDir.var_export($path, true);
|
|
|
+ }
|
|
|
+ $exportedPrefix = var_export($namespace, true);
|
|
|
+ $namespacesFile .= " $exportedPrefix => ";
|
|
|
+ if (count($exportedPaths) > 1) {
|
|
|
+ $namespacesFile .= "array(".implode(', ', $exportedPaths)."),\n";
|
|
|
+ } else {
|
|
|
+ $namespacesFile .= $exportedPaths[0].",\n";
|
|
|
}
|
|
|
}
|
|
|
$namespacesFile .= ");\n";
|
|
|
|
|
|
- if (isset($autoloads['classmap'])) {
|
|
|
-
|
|
|
- $autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
|
|
- } else {
|
|
|
- $autoloads['classmap'] = array();
|
|
|
- }
|
|
|
+ $classmapFile = <<<EOF
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+\$vendorDir = $vendorDirCode;
|
|
|
+\$baseDir = $appBaseDir;
|
|
|
+
|
|
|
+return array(
|
|
|
+
|
|
|
+EOF;
|
|
|
|
|
|
- ClassMapGenerator::dump($autoloads['classmap'], $targetDir.'/autoload_classmap.php');
|
|
|
+
|
|
|
+ $autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
|
|
+ foreach ($autoloads['classmap'] as $dir) {
|
|
|
+ foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
|
|
+ $path = '/'.$filesystem->findShortestPath(getcwd(), $path);
|
|
|
+ $classmapFile .= ' '.var_export($class, true).' => $baseDir . '.var_export($path, true).",\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $classmapFile .= ");\n";
|
|
|
|
|
|
file_put_contents($targetDir.'/autoload.php', $autoloadFile);
|
|
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
|
|
+ file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
|
|
copy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php');
|
|
|
}
|
|
|
|
|
@@ -154,7 +167,7 @@ EOF;
|
|
|
*/
|
|
|
public function parseAutoloads(array $packageMap)
|
|
|
{
|
|
|
- $autoloads = array();
|
|
|
+ $autoloads = array('classmap' => array(), 'psr-0' => array());
|
|
|
foreach ($packageMap as $item) {
|
|
|
list($package, $installPath) = $item;
|
|
|
|