class ClassResolver in Service Container 7
Same name and namespace in other branches
- 7.2 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 ClassResolverInterface, ContainerAwareInterface uses DependencySerializationTrait, ContainerAwareTrait
Expanded class hierarchy of ClassResolver
File
- lib/
Drupal/ Core/ DependencyInjection/ ClassResolver.php, line 16 - Contains \Drupal\Core\DependencyInjection\ClassResolver.
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClassResolver:: |
public | function |
Returns a class instance with a given class definition. Overrides ClassResolverInterface:: |
|
ContainerAwareTrait:: |
protected | property | ||
ContainerAwareTrait:: |
public | function | Sets the Container associated with this Controller. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | ||
DependencySerializationTrait:: |
public | function |