GraphqlTwigServiceProvider   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A alter() 0 13 1
1
<?php
2
3
namespace Drupal\graphql_twig;
4
5
use Drupal\Core\DependencyInjection\ContainerBuilder;
6
use Drupal\Core\DependencyInjection\ServiceProviderBase;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * Service provider to inject a custom derivation of `TwigEnvironment`.
11
 */
12
class GraphqlTwigServiceProvider extends ServiceProviderBase {
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  public function alter(ContainerBuilder $container) {
18
    // Replace the twig environment with the GraphQL enhanced one.
19
    $container->getDefinition('twig')
20
      ->setClass(GraphQLTwigEnvironment::class)
21
      ->addArgument(new Reference('graphql.query_processor'))
22
      ->addArgument(new Reference('renderer'));
23
24
    // Inject our own argument resolver.
25
    $def = $container->getDefinition('http_kernel.controller.argument_resolver');
26
    $argumentResolvers = $def->getArgument(1);
27
    $argumentResolvers[] = new Reference('argument_resolver.graphql_twig');
28
    $def->setArgument(1, $argumentResolvers);
29
  }
30
31
}
32