More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Plugin / TestPluginManager.php
1 <?php
2
3 namespace Drupal\Tests\Core\Plugin;
4
5 use Drupal\Component\Plugin\Discovery\StaticDiscovery;
6 use Drupal\Component\Plugin\Factory\DefaultFactory;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Plugin\DefaultPluginManager;
9
10 /**
11  * A plugin manager for condition plugins.
12  */
13 class TestPluginManager extends DefaultPluginManager {
14
15   /**
16    * Constructs a TestPluginManager object.
17    *
18    * @param \Traversable $namespaces
19    *   An object that implements \Traversable which contains the root paths
20    *   keyed by the corresponding namespace to look for plugin implementations.
21    * @param array $definitions
22    *   An array of static definitions.
23    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
24    *   (optional) The module handler to invoke the alter hook with.
25    * @param string $alter_hook
26    *   (optional) Name of the alter hook.
27    * @param string $interface
28    *   (optional) The interface required for the plugins.
29    */
30   public function __construct(\Traversable $namespaces, array $definitions, ModuleHandlerInterface $module_handler = NULL, $alter_hook = NULL, $interface = NULL) {
31     // Create the object that can be used to return definitions for all the
32     // plugins available for this type. Most real plugin managers use a richer
33     // discovery implementation, but StaticDiscovery lets us add some simple
34     // mock plugins for unit testing.
35     $this->discovery = new StaticDiscovery();
36     $this->factory = new DefaultFactory($this->discovery, $interface);
37
38     // Add the static definitions.
39     foreach ($definitions as $key => $definition) {
40       $this->discovery->setDefinition($key, $definition);
41     }
42
43     $this->moduleHandler = $module_handler;
44
45     if ($alter_hook) {
46       $this->alterInfo($alter_hook);
47     }
48   }
49
50 }