Pārlūkot izejas kodu

Return the composer.json content instead of a zip:// path

Andreas Schempp 6 gadi atpakaļ
vecāks
revīzija
a91fd20673

+ 3 - 5
src/Composer/Repository/ArtifactRepository.php

@@ -83,15 +83,13 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito
 
     private function getComposerInformation(\SplFileInfo $file)
     {
-        $composerFile = Zip::findComposerJson($file->getPathname());
+        $json = Zip::getComposerJson($file->getPathname());
 
-        if (null === $composerFile) {
+        if (null === $json) {
             return false;
         }
 
-        $json = file_get_contents($composerFile);
-
-        $package = JsonFile::parseJson($json, $composerFile);
+        $package = JsonFile::parseJson($json, $file->getPathname().'#composer.json');
         $package['dist'] = array(
             'type' => 'zip',
             'url' => strtr($file->getPathname(), '\\', '/'),

+ 10 - 3
src/Composer/Util/Zip.php

@@ -18,14 +18,14 @@ namespace Composer\Util;
 class Zip
 {
     /**
-     * Finds the path to the root composer.json inside a ZIP archive.
+     * Gets content of the root composer.json inside a ZIP archive.
      *
      * @param string $pathToZip
      * @param string $filename
      *
      * @return string|null
      */
-    public static function findComposerJson($pathToZip)
+    public static function getComposerJson($pathToZip)
     {
         if (!extension_loaded('zip')) {
             throw new \RuntimeException('The Zip Util requires PHP\'s zip extension');
@@ -49,10 +49,17 @@ class Zip
             return null;
         }
 
+        $content = null;
         $configurationFileName = $zip->getNameIndex($foundFileIndex);
+        $stream = $zip->getStream($configurationFileName);
+
+        if (false !== $stream) {
+            $content = stream_get_contents($stream);
+        }
+
         $zip->close();
 
-        return "zip://{$pathToZip}#$configurationFileName";
+        return $content;
     }
 
     /**