function ComposerInspector::validateProject

Checks that `composer.json` is valid and `composer.lock` exists.

Parameters

string $working_dir: The directory to check.

Throws

\Drupal\package_manager\Exception\ComposerNotReadyException Thrown if:

  • `composer.json` doesn't exist in the given directory or is invalid according to `composer validate`.
  • `composer.lock` doesn't exist in the given directory.
2 calls to ComposerInspector::validateProject()
ComposerInspector::getConfig in core/modules/package_manager/src/ComposerInspector.php
Returns a config value from Composer.
ComposerInspector::validate in core/modules/package_manager/src/ComposerInspector.php
Checks that Composer commands can be run.

File

core/modules/package_manager/src/ComposerInspector.php, line 102

Class

ComposerInspector
Defines a class to get information from Composer.

Namespace

Drupal\package_manager

Code

private function validateProject(string $working_dir) : void {
    $messages = [];
    $previous_exception = NULL;
    // If either composer.json or composer.lock have changed, ensure the
    // directory is in a completely valid state, according to Composer.
    if ($this->invalidateCacheIfNeeded($working_dir)) {
        try {
            $this->runner
                ->run([
                'validate',
                '--check-lock',
                '--no-check-publish',
                '--with-dependencies',
                '--no-ansi',
                "--working-dir={$working_dir}",
            ]);
        } catch (RuntimeException $e) {
            $messages[] = $e->getMessage();
            $previous_exception = $e;
        }
    }
    // Check for the presence of composer.lock, because `composer validate`
    // doesn't expect it to exist, but we do (see ::getInstalledPackagesList()).
    if (!file_exists($working_dir . DIRECTORY_SEPARATOR . 'composer.lock')) {
        $messages[] = $this->t('composer.lock not found in @dir.', [
            '@dir' => $working_dir,
        ]);
    }
    if ($messages) {
        throw new ComposerNotReadyException($working_dir, $messages, 0, $previous_exception);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.