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\UtilCode
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;
}