function ClassResolver::getInstanceFromDefinition
Same name in other branches
- 8.9.x core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver::getInstanceFromDefinition()
- 10 core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver::getInstanceFromDefinition()
- 11.x core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver::getInstanceFromDefinition()
Overrides ClassResolverInterface::getInstanceFromDefinition
File
-
core/
lib/ Drupal/ Core/ DependencyInjection/ ClassResolver.php, line 18
Class
- ClassResolver
- Implements the class resolver interface supporting class names and services.
Namespace
Drupal\Core\DependencyInjectionCode
public function getInstanceFromDefinition($definition) {
if ($this->container
->has($definition)) {
$instance = $this->container
->get($definition);
}
else {
if (!class_exists($definition)) {
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $definition));
}
if (is_subclass_of($definition, 'Drupal\\Core\\DependencyInjection\\ContainerInjectionInterface')) {
$instance = $definition::create($this->container);
}
else {
$instance = new $definition();
}
}
if ($instance instanceof ContainerAwareInterface) {
$instance->setContainer($this->container);
}
return $instance;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.