Version 1
[yaffs-website] / web / modules / contrib / devel / src / DevelDumperPluginManager.php
1 <?php
2
3 namespace Drupal\devel;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8 use Drupal\devel\Annotation\DevelDumper;
9
10 /**
11  * Plugin type manager for Devel Dumper plugins.
12  *
13  * @see \Drupal\devel\Annotation\DevelDumper
14  * @see \Drupal\devel\DevelDumperInterface
15  * @see \Drupal\devel\DevelDumperBase
16  * @see plugin_api
17  */
18 class DevelDumperPluginManager extends DefaultPluginManager implements DevelDumperPluginManagerInterface {
19
20   /**
21    * Constructs a DevelDumperPluginManager object.
22    *
23    * @param \Traversable $namespaces
24    *   An object that implements \Traversable which contains the root paths
25    *   keyed by the corresponding namespace to look for plugin implementations.
26    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
27    *   Cache backend instance to use.
28    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
29    *   The module handler to invoke the alter hook with.
30    */
31   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
32     parent::__construct('Plugin/Devel/Dumper', $namespaces, $module_handler, DevelDumperInterface::class, DevelDumper::class);
33     $this->setCacheBackend($cache_backend, 'devel_dumper_plugins');
34     $this->alterInfo('devel_dumper_info');
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function processDefinition(&$definition, $plugin_id) {
41     parent::processDefinition($definition, $plugin_id);
42
43     $definition['supported'] = (bool) call_user_func([$definition['class'], 'checkRequirements']);
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function isPluginSupported($plugin_id) {
50     $definition = $this->getDefinition($plugin_id, FALSE);
51     return $definition && $definition['supported'];
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function createInstance($plugin_id, array $configuration = []) {
58     if (!$this->isPluginSupported($plugin_id)) {
59       $plugin_id = $this->getFallbackPluginId($plugin_id);
60     }
61     return parent::createInstance($plugin_id, $configuration);
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function getFallbackPluginId($plugin_id, array $configuration = []) {
68     return 'default';
69   }
70
71 }