You are here

public static function Dependency::createFromString in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/Dependency.php \Drupal\Core\Extension\Dependency::createFromString()

Creates a new instance of this class from a dependency string.

Parameters

string $dependency: A dependency string, which specifies a module or theme dependency, and optionally the project it comes from and a constraint string that determines the versions that are supported. Supported formats include:

  • 'module'
  • 'project:module'
  • 'project:module (>=version, <=version)'.

Return value

static

2 calls to Dependency::createFromString()
DependencyTest::testCreateFromString in core/tests/Drupal/Tests/Core/Extension/DependencyTest.php
@covers ::createFromString @dataProvider providerCreateFromString
ModuleHandler::buildModuleDependencies in core/lib/Drupal/Core/Extension/ModuleHandler.php
Determines which modules require and are required by each module.

File

core/lib/Drupal/Core/Extension/Dependency.php, line 125

Class

Dependency
A value object representing dependency information.

Namespace

Drupal\Core\Extension

Code

public static function createFromString($dependency) {
  if (strpos($dependency, ':') !== FALSE) {
    list($project, $dependency) = explode(':', $dependency);
  }
  else {
    $project = '';
  }
  $parts = explode('(', $dependency, 2);
  $name = trim($parts[0]);
  $version_string = isset($parts[1]) ? rtrim($parts[1], ") ") : '';
  return new static($name, $project, $version_string);
}