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

Breadcrumb

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

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\Util

Code

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');
}

API Navigation

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