Completed
Pull Request — 8.x-3.x (#503)
by Sebastian
05:46
created

GraphQLUpload::getDefinition()   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\GraphQL\Scalars;
4
5
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
6
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7
use Drupal\graphql\GraphQL\Type\UploadType;
8
use Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
use Symfony\Component\HttpFoundation\RequestStack;
11
12
/**
13
 * @GraphQLScalar(
14
 *   id = "upload",
15
 *   name = "Upload"
16
 * )
17
 */
18
class GraphQLUpload extends ScalarPluginBase implements ContainerFactoryPluginInterface {
0 ignored issues
show
Bug introduced by
There is one abstract method getPluginDefinition in this class; you could implement it, or declare this class as abstract.
Loading history...
19
  use DependencySerializationTrait;
20
21
  /**
22
   * The request stack.
23
   *
24
   * @var \Symfony\Component\HttpFoundation\RequestStack
25
   */
26
  protected $requestStack;
27
28
  /**
29
   * GraphQLUpload constructor.
30
   *
31
   * @param array $configuration
32
   *   The plugin configuration array.
33
   * @param string $pluginId
34
   *   The plugin id.
35
   * @param array $pluginDefinition
36
   *   The plugin definition array.
37
   * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
38
   *   The request stack.
39
   */
40
  public function __construct(array $configuration, $pluginId, $pluginDefinition, RequestStack $requestStack) {
41
    parent::__construct($configuration, $pluginId, $pluginDefinition);
42
    $this->requestStack = $requestStack;
43
  }
44
45
  /**
46
   * {@inheritdoc}
47
   */
48
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
49
    return new static(
50
      $configuration,
51
      $pluginId,
52
      $pluginDefinition,
53
      $container->get('request_stack')
54
    );
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60
  public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) {
61
    if (!isset($this->definition)) {
62
      $this->definition = new UploadType($this->requestStack);
63
    }
64
65
    return $this->definition;
66
  }
67
}
68