1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/******************************************************************************* |
4
|
|
|
* This file is part of the GraphQL Bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) YnloUltratech <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
******************************************************************************/ |
11
|
|
|
|
12
|
|
|
namespace Ynlo\GraphQLBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
18
|
|
|
use Ynlo\GraphQLBundle\Cache\DefinitionCacheWarmer; |
19
|
|
|
use Ynlo\GraphQLBundle\GraphiQL\JWTGraphiQLAuthentication; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class YnloGraphQLExtension |
23
|
|
|
*/ |
24
|
|
|
class YnloGraphQLExtension extends Extension |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function load(array $configs, ContainerBuilder $container) |
30
|
|
|
{ |
31
|
|
|
$configuration = new Configuration($container->getParameter('kernel.debug')); |
|
|
|
|
32
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
33
|
|
|
|
34
|
|
|
if (!isset($config['definitions']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'])) { |
35
|
|
|
$config['definitions']['extensions']['namespaces']['bundles']['aliases']['GraphQLBundle'] = 'AppBundle'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$container->setParameter('graphql.config', $config); |
39
|
|
|
if (isset($config['definitions']['extensions'])) { |
40
|
|
|
foreach ($config['definitions']['extensions'] as $extension => $extConfig) { |
41
|
|
|
$extConfig = isset($extConfig['enabled']) && $extConfig['enabled'] ? $extConfig : []; |
42
|
|
|
$container->setParameter('graphql.extension_config.'.$extension, $extConfig ?? []); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$container->setParameter('graphql.cors_config', $config['cors'] ?? []); |
47
|
|
|
$container->setParameter('graphql.graphiql', $config['graphiql'] ?? []); |
48
|
|
|
$container->setParameter('graphql.graphiql_auth_jwt', $config['graphiql']['authentication']['provider']['jwt'] ?? []); |
49
|
|
|
|
50
|
|
|
$graphiQLAuthProvider = null; |
51
|
|
|
if ($config['graphiql']['authentication']['provider']['jwt']['enabled'] ?? false) { |
52
|
|
|
$graphiQLAuthProvider = JWTGraphiQLAuthentication::class; |
53
|
|
|
} |
54
|
|
|
if ($config['graphiql']['authentication']['provider']['custom'] ?? false) { |
55
|
|
|
$graphiQLAuthProvider = $config['graphiql']['authentication']['provider']['custom']; |
56
|
|
|
} |
57
|
|
|
$container->setParameter('graphql.graphiql_auth_provider', $graphiQLAuthProvider); |
58
|
|
|
|
59
|
|
|
$configDir = __DIR__.'/../Resources/config'; |
60
|
|
|
$loader = new YamlFileLoader($container, new FileLocator($configDir)); |
61
|
|
|
$loader->load('services.yml'); |
62
|
|
|
|
63
|
|
|
if (!$container->getParameter('kernel.debug')) { |
64
|
|
|
$container->getDefinition(DefinitionCacheWarmer::class)->clearTag('kernel.event_subscriber'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
|
|
public function getAlias() |
72
|
|
|
{ |
73
|
|
|
return 'graphql'; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.