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 { |
|
|
|
|
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
|
|
|
|