Przeglądaj źródła

Fixed error, when composer.phar was broken, if it compiled inside folder, that has /composer in path

Fedir Kryvytskyi 7 lat temu
rodzic
commit
dc509b236f
1 zmienionych plików z 16 dodań i 2 usunięć
  1. 16 2
      src/Composer/Compiler.php

+ 16 - 2
src/Composer/Compiler.php

@@ -164,10 +164,24 @@ class Compiler
         $util->save($pharFile, \Phar::SHA1);
     }
 
-    private function addFile($phar, $file, $strip = true)
+    /**
+     * @param \SplFileInfo $file
+     * @return string
+     */
+    private function getRelativeFilePath($file)
     {
-        $path = strtr(str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/');
+        $realPath = $file->getRealPath();
+        $pathPrefix = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR;
+
+        $pos = strpos($realPath, $pathPrefix);
+        $relativePath = ($pos !== false) ? substr_replace($realPath, '', $pos, strlen($pathPrefix)) : $realPath;
 
+        return strtr($relativePath, '\\', '/');
+    }
+
+    private function addFile($phar, $file, $strip = true)
+    {
+        $path = $this->getRelativeFilePath($file);
         $content = file_get_contents($file);
         if ($strip) {
             $content = $this->stripWhitespace($content);