Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/DependencyInjection/ClassResolver.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\DependencyInjection; | |
4 | |
5 use Symfony\Component\DependencyInjection\ContainerAwareTrait; | |
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
7 | |
8 /** | |
9 * Implements the class resolver interface supporting class names and services. | |
10 */ | |
11 class ClassResolver implements ClassResolverInterface, ContainerAwareInterface { | |
12 use DependencySerializationTrait; | |
13 use ContainerAwareTrait; | |
14 | |
15 /** | |
16 * {@inheritdoc} | |
17 */ | |
18 public function getInstanceFromDefinition($definition) { | |
19 if ($this->container->has($definition)) { | |
20 $instance = $this->container->get($definition); | |
21 } | |
22 else { | |
23 if (!class_exists($definition)) { | |
24 throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $definition)); | |
25 } | |
26 | |
27 if (is_subclass_of($definition, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) { | |
28 $instance = $definition::create($this->container); | |
29 } | |
30 else { | |
31 $instance = new $definition(); | |
32 } | |
33 } | |
34 | |
35 if ($instance instanceof ContainerAwareInterface) { | |
36 $instance->setContainer($this->container); | |
37 } | |
38 | |
39 return $instance; | |
40 } | |
41 | |
42 } |