Completed
Pull Request — 8.x-3.x (#525)
by Philipp
08:20
created

TypePluginManager::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin;
4
5
use Drupal\Core\Cache\CacheBackendInterface;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\DefaultPluginManager;
8
9
class TypePluginManager extends DefaultPluginManager implements TypePluginManagerInterface {
10
11
  /**
12
   * Static cache of plugin instances.
13
   *
14
   * @var \Drupal\graphql\Plugin\TypePluginInterface[]
15
   */
16
  protected $instances;
17
18
  /**
19
   * TypePluginManager constructor.
20
   *
21
   * @param bool|string $pluginSubdirectory
22
   *   The plugin's subdirectory.
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\Extension\ModuleHandlerInterface $moduleHandler
27
   *   The module handler.
28
   * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
29
   *   The cache backend.
30
   * @param string|null $pluginInterface
31
   *   The interface each plugin should implement.
32
   * @param string $pluginAnnotationName
33
   *   The name of the annotation that contains the plugin definition.
34
   * @param string $pluginType
35
   *   The plugin type.
36
   */
37
  public function __construct(
38
    $pluginSubdirectory,
39
    \Traversable $namespaces,
40
    ModuleHandlerInterface $moduleHandler,
41
    CacheBackendInterface $cacheBackend,
42
    $pluginInterface,
43
    $pluginAnnotationName,
44
    $pluginType
45
  ) {
46
    parent::__construct(
47
      $pluginSubdirectory,
48
      $namespaces,
49
      $moduleHandler,
50
      $pluginInterface,
51
      $pluginAnnotationName
52
    );
53
54
    $this->alterInfo("graphql_{$pluginType}");
55
    $this->useCaches(TRUE);
56
    $this->setCacheBackend($cacheBackend, $pluginType, ['graphql', "graphql:{$pluginType}"]);
57
  }
58
59
  /**
60
   * {@inheritdoc}
61
   */
62
  public function getInstance(array $options) {
63
    if (!isset($this->instances[$options['id']])) {
64
      $this->instances[$options['id']] = $this->createInstance($options['id']);
65
    }
66
67
    return $this->instances[$options['id']];
68
  }
69
70
}
71