1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Provider\CacheProvider; |
6
|
|
|
use Digia\GraphQL\Provider\DirectivesProvider; |
7
|
|
|
use Digia\GraphQL\Provider\ParserProvider; |
8
|
|
|
use Digia\GraphQL\Provider\PrinterProvider; |
9
|
|
|
use Digia\GraphQL\Provider\ScalarTypesProvider; |
10
|
|
|
use Digia\GraphQL\Provider\SchemaBuilderProvider; |
11
|
|
|
use League\Container\Container; |
12
|
|
|
use League\Container\ContainerInterface; |
13
|
|
|
|
14
|
|
|
class GraphQL |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public const BOOLEAN = 'GraphQLBoolean'; |
18
|
|
|
public const FLOAT = 'GraphQLFloat'; |
19
|
|
|
public const INT = 'GraphQLInt'; |
20
|
|
|
public const ID = 'GraphQLID'; |
21
|
|
|
public const STRING = 'GraphQLString'; |
22
|
|
|
|
23
|
|
|
public const DEPRECATED_DIRECTIVE = 'GraphQLDeprecatedDirective'; |
24
|
|
|
public const INCLUDE_DIRECTIVE = 'GraphQLIncludeDirective'; |
25
|
|
|
public const SKIP_DIRECTIVE = 'GraphQLSkipDirective'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private static $providers = [ |
31
|
|
|
CacheProvider::class, |
32
|
|
|
ParserProvider::class, |
33
|
|
|
PrinterProvider::class, |
34
|
|
|
SchemaBuilderProvider::class, |
35
|
|
|
ScalarTypesProvider::class, |
36
|
|
|
DirectivesProvider::class, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var GraphQL |
41
|
|
|
*/ |
42
|
|
|
private static $instance; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Container |
46
|
|
|
*/ |
47
|
|
|
protected $container; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* GraphQL constructor. |
51
|
|
|
*/ |
52
|
|
|
private function __construct() |
53
|
|
|
{ |
54
|
|
|
$container = new Container(); |
55
|
|
|
|
56
|
|
|
$this->registerProviders($container); |
57
|
|
|
|
58
|
|
|
$this->container = $container; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Registers the service provides with the container. |
63
|
|
|
*/ |
64
|
|
|
protected function registerProviders(ContainerInterface $container): void |
65
|
|
|
{ |
66
|
|
|
foreach (self::$providers as $className) { |
67
|
|
|
$container->addServiceProvider(new $className()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return GraphQL |
73
|
|
|
*/ |
74
|
|
|
public static function getInstance(): self |
75
|
|
|
{ |
76
|
|
|
if (null === self::$instance) { |
77
|
|
|
self::$instance = new static(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return self::$instance; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $id |
85
|
|
|
* @param array $args |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
|
|
public static function get(string $id, array $args = []) |
89
|
|
|
{ |
90
|
|
|
return self::getInstance()->getContainer()->get($id, $args); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return Container |
95
|
|
|
*/ |
96
|
|
|
public function getContainer(): Container |
97
|
|
|
{ |
98
|
|
|
return $this->container; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|