b608e90b82a5cd61156dcbc2a20f90cd64f9787e
[yaffs-website] / web / core / lib / Drupal / Component / Plugin / PluginBase.php
1 <?php
2
3 namespace Drupal\Component\Plugin;
4
5 /**
6  * Base class for plugins wishing to support metadata inspection.
7  */
8 abstract class PluginBase implements PluginInspectionInterface, DerivativeInspectionInterface {
9
10   /**
11    * A string which is used to separate base plugin IDs from the derivative ID.
12    */
13   const DERIVATIVE_SEPARATOR = ':';
14
15   /**
16    * The plugin_id.
17    *
18    * @var string
19    */
20   protected $pluginId;
21
22   /**
23    * The plugin implementation definition.
24    *
25    * @var array
26    */
27   protected $pluginDefinition;
28
29   /**
30    * Configuration information passed into the plugin.
31    *
32    * When using an interface like
33    * \Drupal\Component\Plugin\ConfigurablePluginInterface, this is where the
34    * configuration should be stored.
35    *
36    * Plugin configuration is optional, so plugin implementations must provide
37    * their own setters and getters.
38    *
39    * @var array
40    */
41   protected $configuration;
42
43   /**
44    * Constructs a Drupal\Component\Plugin\PluginBase object.
45    *
46    * @param array $configuration
47    *   A configuration array containing information about the plugin instance.
48    * @param string $plugin_id
49    *   The plugin_id for the plugin instance.
50    * @param mixed $plugin_definition
51    *   The plugin implementation definition.
52    */
53   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
54     $this->configuration = $configuration;
55     $this->pluginId = $plugin_id;
56     $this->pluginDefinition = $plugin_definition;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function getPluginId() {
63     return $this->pluginId;
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function getBaseId() {
70     $plugin_id = $this->getPluginId();
71     if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
72       list($plugin_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
73     }
74     return $plugin_id;
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function getDerivativeId() {
81     $plugin_id = $this->getPluginId();
82     $derivative_id = NULL;
83     if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
84       list(, $derivative_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
85     }
86     return $derivative_id;
87   }
88
89   /**
90    * {@inheritdoc}
91    */
92   public function getPluginDefinition() {
93     return $this->pluginDefinition;
94   }
95
96 }