ArgumentResolver::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_twig\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
7
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
8
9
/**
10
 * Custom argument resolver with specific argument handling.
11
 *
12
 * Matches routes generated by GraphQL Twig and massages arguments accordingly.
13
 *
14
 * @package Drupal\graphql_twig\Controller
15
 */
16
class ArgumentResolver implements ArgumentValueResolverInterface {
17
18
  /**
19
   * @inheritdoc
20
   */
21
  public function supports(Request $request, ArgumentMetadata $argument) {
22
    return in_array($argument->getName(), [
23
      '_graphql_arguments',
24
      '_graphql_theme_hook',
25
      '_graphql_title',
26
      '_graphql_title_query',
27
    ]);
28
  }
29
30
  /**
31
   * @inheritdoc
32
   */
33
  public function resolve(Request $request, ArgumentMetadata $argument) {
34
    switch($argument->getName()) {
35
      case '_graphql_arguments':
36
        yield $request->attributes->get('_raw_variables')->all();
37
        break;
38
      case '_graphql_theme_hook':
39
        yield $request->attributes->get('_theme_hook');
40
        break;
41
      case '_graphql_title':
42
        yield $request->attributes->get('_title');
43
        break;
44
      case '_graphql_title_query':
45
        yield $request->attributes->get('_title_query');
46
        break;
47
    }
48
  }
49
50
51
}
52