You are here

public function Container::getDefinition in Service Container 7

Same name and namespace in other branches
  1. 7.2 src/DependencyInjection/Container.php \Drupal\service_container\DependencyInjection\Container::getDefinition()

Gets a specific plugin definition.

Parameters

string $plugin_id: A plugin id.

bool $exception_on_invalid: (optional) If TRUE, an invalid plugin ID will throw an exception.

Return value

mixed A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE.

Overrides DiscoveryInterface::getDefinition

File

src/DependencyInjection/Container.php, line 38
Contains \Drupal\service_container\DependencyInjection\Container

Class

Container
Container is a DI container that provides services to users of the class.

Namespace

Drupal\service_container\DependencyInjection

Code

public function getDefinition($plugin_id, $exception_on_invalid = TRUE) {
  $definition = isset($this->serviceDefinitions[$plugin_id]) ? $this->serviceDefinitions[$plugin_id] : NULL;
  if (!$definition && $exception_on_invalid) {
    throw new RuntimeException(sprintf('The "%s" service definition does not exist.', $plugin_id));
  }
  return $definition;
}