function Tar::extractComposerJsonFromFolder
Throws
\RuntimeException
1 call to Tar::extractComposerJsonFromFolder()
- Tar::getComposerJson in vendor/
composer/ composer/ src/ Composer/ Util/ Tar.php
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Tar.php, line 34
Class
- Tar
- @author Wissem Riahi <wissemr@gmail.com>
Namespace
Composer\UtilCode
private static function extractComposerJsonFromFolder(\PharData $phar) : string {
if (isset($phar['composer.json'])) {
return $phar['composer.json']->getContent();
}
$topLevelPaths = [];
foreach ($phar as $folderFile) {
$name = $folderFile->getBasename();
if ($folderFile->isDir()) {
$topLevelPaths[$name] = true;
if (\count($topLevelPaths) > 1) {
throw new \RuntimeException('Archive has more than one top level directories, and no composer.json was found on the top level, so it\'s an invalid archive. Top level paths found were: ' . implode(',', array_keys($topLevelPaths)));
}
}
}
$composerJsonPath = key($topLevelPaths) . '/composer.json';
if ($topLevelPaths && isset($phar[$composerJsonPath])) {
return $phar[$composerJsonPath]->getContent();
}
throw new \RuntimeException('No composer.json found either at the top level or within the topmost directory');
}