function SandboxManagerBase::validateRequirements

Validates a set of package names.

Package names are considered invalid if they look like Drupal project names. The only exceptions to this are platform requirements, like `php`, `composer`, or `ext-json`, which are legitimate to Composer.

Parameters

string[] $requirements: A set of package names (with or without version constraints), as passed to ::require().

Throws

\InvalidArgumentException Thrown if any of the given package names fail basic validation.

1 call to SandboxManagerBase::validateRequirements()
SandboxManagerBase::require in core/modules/package_manager/src/SandboxManagerBase.php
Adds or updates packages in the sandbox directory.

File

core/modules/package_manager/src/SandboxManagerBase.php, line 847

Class

SandboxManagerBase
Creates and manages a stage directory in which to install or update code.

Namespace

Drupal\package_manager

Code

protected static function validateRequirements(array $requirements) : void {
  $version_parser = new VersionParser();
  foreach ($requirements as $requirement) {
    $parts = explode(':', $requirement, 2);
    $name = $parts[0];
    if (!preg_match(self::COMPOSER_PLATFORM_PACKAGE_REGEX, $name) && !preg_match(self::COMPOSER_PACKAGE_REGEX, $name)) {
      throw new \InvalidArgumentException("Invalid package name '{$name}'.");
    }
    if (count($parts) > 1) {
      $version_parser->parseConstraints($parts[1]);
    }
  }
}

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