You are here

public function Container::getSpec in Little helpers 7.2

Get a spec to for creating a new instance of the referenced class.

Parameters

string $name: Name of the spec to be loaded.

bool $exception: Whether to throw an exception if no spec with the name exists. If FALSE then a boolean FALSE will be returned instead.

Return value

\Drupal\little_helpers\Services\Spec The registered spec for the $name.

1 call to Container::getSpec()
Container::loadService in src/Services/Container.php
Load a (possibly cached) service by name.

File

src/Services/Container.php, line 174

Class

Container
Dependency injection container.

Namespace

Drupal\little_helpers\Services

Code

public function getSpec(string $name, bool $exception = TRUE) {
  if ($spec = $this->specs[$name] ?? NULL) {
    $spec = Spec::fromInfo($spec);
    $spec
      ->setContainer($this->container ?? $this);
    return $spec;
  }
  if ($exception) {
    throw new UnknownServiceException("Unknown service: {$name}");
  }
  return FALSE;
}