From 3cc5698e7bcb3efb9384055393dbd48f3d2d5b76 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 27 Mar 2013 18:45:27 +0100 Subject: [PATCH] Allow PHP 5.2 autoloaders to consume namespace, classmap and include path files, fixes #1730 --- src/Composer/Autoload/AutoloadGenerator.php | 7 ++++--- tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 4 ++-- .../Composer/Test/Autoload/Fixtures/autoload_classmap.php | 2 +- .../Composer/Test/Autoload/Fixtures/autoload_classmap2.php | 2 +- .../Composer/Test/Autoload/Fixtures/autoload_classmap3.php | 2 +- .../Composer/Test/Autoload/Fixtures/autoload_classmap4.php | 2 +- .../Composer/Test/Autoload/Fixtures/autoload_classmap5.php | 2 +- .../Composer/Test/Autoload/Fixtures/autoload_classmap6.php | 2 +- tests/Composer/Test/Autoload/Fixtures/autoload_main.php | 2 +- tests/Composer/Test/Autoload/Fixtures/autoload_main2.php | 2 +- tests/Composer/Test/Autoload/Fixtures/autoload_main3.php | 2 +- tests/Composer/Test/Autoload/Fixtures/autoload_vendors.php | 2 +- tests/Composer/Test/Autoload/Fixtures/include_paths.php | 2 +- 13 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index c0ebafe61..fce0756c3 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -48,6 +48,7 @@ class AutoloadGenerator $relVendorPath = $filesystem->findShortestPath(getcwd(), $vendorPath, true); $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); + $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, getcwd(), true); @@ -58,7 +59,7 @@ class AutoloadGenerator // autoload_namespaces.php generated by Composer -\$vendorDir = $vendorPathCode; +\$vendorDir = $vendorPathCode52; \$baseDir = $appBaseDirCode; return array( @@ -88,7 +89,7 @@ EOF; // autoload_classmap.php generated by Composer -\$vendorDir = $vendorPathCode; +\$vendorDir = $vendorPathCode52; \$baseDir = $appBaseDirCode; return array( @@ -180,7 +181,7 @@ EOF; 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)) { + if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($targetDir.'/include_paths.php', $includePathFile); } file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 32d8bd7a6..5fff7b6e5 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -475,7 +475,7 @@ class AutoloadGeneratorTest extends TestCase // autoload_namespaces.php generated by Composer -\$vendorDir = dirname(__DIR__); +\$vendorDir = dirname(dirname(__FILE__)); \$baseDir = dirname(\$vendorDir); return array( @@ -491,7 +491,7 @@ EOF; // autoload_classmap.php generated by Composer -\$vendorDir = dirname(__DIR__); +\$vendorDir = dirname(dirname(__FILE__)); \$baseDir = dirname(\$vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php index 9e9da840b..d74b484d8 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php index 6016af10e..7870c251e 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname($vendorDir)); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php index 9c5136d7f..cda9a4d82 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = $vendorDir; return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php index 8896cdfb8..f6731f823 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php index 0a1f5def8..1fb28ec5a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap6.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap6.php index 2af6e58fd..b45bf60c3 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap6.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap6.php @@ -2,7 +2,7 @@ // autoload_classmap.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main.php index 613cddbe2..be588255f 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_main.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main.php @@ -2,7 +2,7 @@ // autoload_namespaces.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main2.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main2.php index d857655af..93d797879 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_main2.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main2.php @@ -2,7 +2,7 @@ // autoload_namespaces.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname($vendorDir)); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php index 7fb27d0bd..5a98309e0 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php @@ -2,7 +2,7 @@ // autoload_namespaces.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = $vendorDir; return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_vendors.php b/tests/Composer/Test/Autoload/Fixtures/autoload_vendors.php index f77821f9a..bb589771c 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_vendors.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_vendors.php @@ -2,7 +2,7 @@ // autoload_namespaces.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( diff --git a/tests/Composer/Test/Autoload/Fixtures/include_paths.php b/tests/Composer/Test/Autoload/Fixtures/include_paths.php index 37ac66c87..64aa4d15f 100644 --- a/tests/Composer/Test/Autoload/Fixtures/include_paths.php +++ b/tests/Composer/Test/Autoload/Fixtures/include_paths.php @@ -2,7 +2,7 @@ // include_paths.php generated by Composer -$vendorDir = dirname(__DIR__); +$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array(