Explorar o código

Re-use existing autoloader suffix if available, fixes #3701

Jordi Boggiano %!s(int64=10) %!d(string=hai) anos
pai
achega
b296e654eb
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      src/Composer/Autoload/AutoloadGenerator.php

+ 10 - 1
src/Composer/Autoload/AutoloadGenerator.php

@@ -214,7 +214,16 @@ EOF;
         $classmapFile .= ");\n";
 
         if (!$suffix) {
-            $suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
+            if (is_readable($vendorPath.'/autoload.php')) {
+                $content = file_get_contents($vendorPath.'/autoload.php');
+                if (preg_match('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
+                    $suffix = $match[1];
+                }
+            }
+
+            if (!$suffix) {
+                $suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
+            }
         }
 
         file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);