Completed
Pull Request — 8.x-3.x (#442)
by Sebastian
02:39
created

SchemaPluginManager::getSchemaBuilder()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL;
4
5
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\DefaultPluginManager;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
use Traversable;
10
11
class SchemaPluginManager extends DefaultPluginManager {
12
13
  /**
14
   * Static cache for plugin instances.
15
   *
16
   * @var object[]
17
   */
18
  protected $instances = [];
19
20
  /**
21
   * The dependency injection container.
22
   *
23
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
24
   */
25
  protected $container;
26
27
  /**
28
   * {@inheritdoc}
29
   */
30
  public function __construct(
31
    $pluginSubdirectory,
32
    Traversable $namespaces,
33
    ModuleHandlerInterface $moduleHandler,
34
    $pluginInterface,
35
    $pluginAnnotationName,
36
    $pluginType,
37
    ContainerInterface $container
38
  ) {
39
    $this->container = $container;
40
    $this->alterInfo($pluginType);
41
42
    parent::__construct(
43
      $pluginSubdirectory,
44
      $namespaces,
45
      $moduleHandler,
46
      $pluginInterface,
47
      $pluginAnnotationName
48
    );
49
  }
50
51
  /**
52
   * {@inheritdoc}
53
   */
54
  public function createInstance($pluginId, array $configuration = []) {
55
    if (!array_key_exists($pluginId, $this->instances)) {
56
      $this->instances[$pluginId] = parent::createInstance($pluginId);
57
      if (!$this->instances[$pluginId] instanceof SchemaPluginInterface) {
58
        throw new \LogicException(sprintf('Plugin %s does not implement \Drupal\graphql\Plugin\GraphQL\SchemaPluginInterface.', $pluginId));
59
      }
60
    }
61
62
    return $this->instances[$pluginId];
63
  }
64
65
}
66