class ClassResolver
Same name in other branches
- 8.9.x core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver
- 10 core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver
- 11.x core/lib/Drupal/Core/DependencyInjection/ClassResolver.php \Drupal\Core\DependencyInjection\ClassResolver
Implements the class resolver interface supporting class names and services.
Hierarchy
- class \Drupal\Core\DependencyInjection\ClassResolver implements \Drupal\Core\DependencyInjection\ClassResolverInterface, \Symfony\Component\DependencyInjection\ContainerAwareInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Symfony\Component\DependencyInjection\ContainerAwareTrait
Expanded class hierarchy of ClassResolver
2 files declare their use of ClassResolver
- ControllerResolverTest.php in core/
tests/ Drupal/ Tests/ Core/ Controller/ ControllerResolverTest.php - Contains \Drupal\Tests\Core\Controller\ControllerResolverTest.
- ThemeNegotiatorTest.php in core/
tests/ Drupal/ Tests/ Core/ Theme/ ThemeNegotiatorTest.php
1 string reference to 'ClassResolver'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ClassResolver
File
-
core/
lib/ Drupal/ Core/ DependencyInjection/ ClassResolver.php, line 11
Namespace
Drupal\Core\DependencyInjectionView source
class ClassResolver implements ClassResolverInterface, ContainerAwareInterface {
use DependencySerializationTrait;
use ContainerAwareTrait;
/**
* {@inheritdoc}
*/
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;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ClassResolver::getInstanceFromDefinition | public | function | Returns a class instance with a given class definition. | Overrides ClassResolverInterface::getInstanceFromDefinition | |
DependencySerializationTrait::$_entityStorages | protected | property | |||
DependencySerializationTrait::$_serviceIds | protected | property | |||
DependencySerializationTrait::__sleep | public | function | 1 | ||
DependencySerializationTrait::__wakeup | public | function | 2 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.