Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Component / Plugin / Discovery / StaticDiscoveryDecorator.php
1 <?php
2
3 namespace Drupal\Component\Plugin\Discovery;
4
5 /**
6  * A decorator that allows manual registration of undiscoverable definitions.
7  */
8 class StaticDiscoveryDecorator extends StaticDiscovery {
9
10   /**
11    * The Discovery object being decorated.
12    *
13    * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface
14    */
15   protected $decorated;
16
17   /**
18    * A callback or closure used for registering additional definitions.
19    *
20    * @var \Callable
21    */
22   protected $registerDefinitions;
23
24   /**
25    * Constructs a \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator object.
26    *
27    * @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
28    *   The discovery object that is being decorated.
29    * @param \Callable $registerDefinitions
30    *   (optional) A callback or closure used for registering additional
31    *   definitions.
32    */
33   public function __construct(DiscoveryInterface $decorated, $registerDefinitions = NULL) {
34     $this->decorated = $decorated;
35     $this->registerDefinitions = $registerDefinitions;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE) {
42     if (isset($this->registerDefinitions)) {
43       call_user_func($this->registerDefinitions);
44     }
45     $this->definitions += $this->decorated->getDefinitions();
46     return parent::getDefinition($base_plugin_id, $exception_on_invalid);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getDefinitions() {
53     if (isset($this->registerDefinitions)) {
54       call_user_func($this->registerDefinitions);
55     }
56     $this->definitions += $this->decorated->getDefinitions();
57     return parent::getDefinitions();
58   }
59
60   /**
61    * Passes through all unknown calls onto the decorated object
62    */
63   public function __call($method, $args) {
64     return call_user_func_array([$this->decorated, $method], $args);
65   }
66
67 }