Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Zip.php

function Zip::getComposerJson

Gets content of the root composer.json inside a ZIP archive.

1 call to Zip::getComposerJson()
ArtifactRepository::getComposerInformation in vendor/composer/composer/src/Composer/Repository/ArtifactRepository.php

File

vendor/composer/composer/src/Composer/Util/Zip.php, line 23

Class

Zip
@author Andreas Schempp <andreas.schempp@terminal42.ch>

Namespace

Composer\Util

Code

public static function getComposerJson(string $pathToZip) : ?string {
    if (!extension_loaded('zip')) {
        throw new \RuntimeException('The Zip Util requires PHP\'s zip extension');
    }
    $zip = new \ZipArchive();
    if ($zip->open($pathToZip) !== true) {
        return null;
    }
    if (0 === $zip->numFiles) {
        $zip->close();
        return null;
    }
    $foundFileIndex = self::locateFile($zip, 'composer.json');
    $content = null;
    $configurationFileName = $zip->getNameIndex($foundFileIndex);
    $stream = $zip->getStream($configurationFileName);
    if (false !== $stream) {
        $content = stream_get_contents($stream);
    }
    $zip->close();
    return $content;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal