1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains \Drupal\service_container\Plugin\PluginManagerBase |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Drupal\service_container\Plugin; |
9
|
|
|
|
10
|
|
|
use Drupal\Component\Plugin\Exception\PluginNotFoundException; |
11
|
|
|
use Drupal\Component\Plugin\FallbackPluginManagerInterface; |
12
|
|
|
use Drupal\Component\Plugin\PluginManagerInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base class for plugin managers. |
16
|
|
|
*/ |
17
|
|
|
abstract class PluginManagerBase implements PluginManagerInterface { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The object that discovers plugins managed by this manager. |
21
|
|
|
* |
22
|
|
|
* @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface |
23
|
|
|
*/ |
24
|
|
|
protected $discovery; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The object that instantiates plugins managed by this manager. |
28
|
|
|
* |
29
|
|
|
* @var \Drupal\Component\Plugin\Factory\FactoryInterface |
30
|
|
|
*/ |
31
|
|
|
protected $factory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { |
37
|
|
|
return $this->discovery->getDefinition($plugin_id, $exception_on_invalid); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function getDefinitions() { |
44
|
|
|
return $this->discovery->getDefinitions(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function hasDefinition($plugin_id) { |
51
|
|
|
return (bool) $this->discovery->hasDefinition($plugin_id); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function createInstance($plugin_id, array $configuration = array()) { |
58
|
|
|
// If this PluginManager has fallback capabilities catch |
59
|
|
|
// PluginNotFoundExceptions. |
60
|
|
|
if ($this instanceof FallbackPluginManagerInterface) { |
61
|
|
|
try { |
62
|
|
|
return $this->factory->createInstance($plugin_id, $configuration); |
63
|
|
|
} |
64
|
|
|
catch (PluginNotFoundException $e) { |
65
|
|
|
$fallback_id = $this->getFallbackPluginId($plugin_id, $configuration); |
|
|
|
|
66
|
|
|
return $this->factory->createInstance($fallback_id, $configuration); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
else { |
70
|
|
|
return $this->factory->createInstance($plugin_id, $configuration); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function getInstance(array $options) { |
78
|
|
|
// 90% of core does not use the generic $mapper functionality, so use a |
79
|
|
|
// sane default function. |
80
|
|
|
if (isset($options['id'])) { |
81
|
|
|
return $this->createInstance($options['id']); |
82
|
|
|
} |
83
|
|
|
return FALSE; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.