Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
CRAP | |
66.67% |
8 / 12 |
| StaticDiscoveryDecorator | |
0.00% |
0 / 1 |
|
50.00% |
2 / 4 |
7.33 | |
66.67% |
8 / 12 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| getDefinition | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| getDefinitions | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| __call | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator. | |
| */ | |
| namespace Drupal\Component\Plugin\Discovery; | |
| /** | |
| * A decorator that allows manual registration of undiscoverable definitions. | |
| */ | |
| class StaticDiscoveryDecorator extends StaticDiscovery { | |
| /** | |
| * The Discovery object being decorated. | |
| * | |
| * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface | |
| */ | |
| protected $decorated; | |
| /** | |
| * A callback or closure used for registering additional definitions. | |
| * | |
| * @var \Callable | |
| */ | |
| protected $registerDefinitions; | |
| /** | |
| * Constructs a \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator object. | |
| * | |
| * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated | |
| * The discovery object that is being decorated. | |
| * @param \Callable $registerDefinitions | |
| * (optional) A callback or closure used for registering additional | |
| * definitions. | |
| */ | |
| public function __construct(DiscoveryInterface $decorated, $registerDefinitions = NULL) { | |
| $this->decorated = $decorated; | |
| $this->registerDefinitions = $registerDefinitions; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE) { | |
| if (isset($this->registerDefinitions)) { | |
| call_user_func($this->registerDefinitions); | |
| } | |
| $this->definitions += $this->decorated->getDefinitions(); | |
| return parent::getDefinition($base_plugin_id, $exception_on_invalid); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getDefinitions() { | |
| if (isset($this->registerDefinitions)) { | |
| call_user_func($this->registerDefinitions); | |
| } | |
| $this->definitions += $this->decorated->getDefinitions(); | |
| return parent::getDefinitions(); | |
| } | |
| /** | |
| * Passes through all unknown calls onto the decorated object | |
| */ | |
| public function __call($method, $args) { | |
| return call_user_func_array(array($this->decorated, $method), $args); | |
| } | |
| } |