1 | <?php |
||
2 | |||
3 | namespace Drupal\graphql\Controller; |
||
4 | |||
5 | use Drupal\Core\Controller\ControllerBase; |
||
0 ignored issues
–
show
|
|||
6 | use Drupal\Core\Language\LanguageManagerInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Language\LanguageManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
7 | use Drupal\Core\Render\RenderContext; |
||
0 ignored issues
–
show
The type
Drupal\Core\Render\RenderContext was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
8 | use Drupal\Core\Render\RendererInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Render\RendererInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
9 | use Drupal\graphql\GraphQL\Buffers\SubRequestResponse; |
||
10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
0 ignored issues
–
show
The type
Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
11 | use Symfony\Component\HttpFoundation\RequestStack; |
||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\RequestStack was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
12 | |||
13 | /** |
||
14 | * Extract arbitrary information from subrequests. |
||
15 | */ |
||
16 | class SubrequestExtractionController extends ControllerBase { |
||
17 | |||
18 | /** |
||
19 | * The symfony request stack. |
||
20 | * |
||
21 | * @var \Symfony\Component\HttpFoundation\RequestStack |
||
22 | */ |
||
23 | protected $requestStack; |
||
24 | |||
25 | /** |
||
26 | * The renderer service. |
||
27 | * |
||
28 | * @var \Drupal\Core\Render\RendererInterface |
||
29 | */ |
||
30 | protected $renderer; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public static function create(ContainerInterface $container) { |
||
36 | return new static( |
||
37 | $container->get('request_stack'), |
||
38 | $container->get('language_manager'), |
||
39 | $container->get('renderer') |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * SubrequestExtractionController constructor. |
||
45 | * |
||
46 | * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
||
47 | * The request stack. |
||
48 | * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager |
||
49 | * The language manager service. |
||
50 | * @param \Drupal\Core\Render\RendererInterface $renderer |
||
51 | * The rewnderer service. |
||
52 | */ |
||
53 | public function __construct(RequestStack $requestStack, LanguageManagerInterface $languageManager, RendererInterface $renderer) { |
||
54 | $this->requestStack = $requestStack; |
||
55 | $this->languageManager = $languageManager; |
||
0 ignored issues
–
show
|
|||
56 | $this->renderer = $renderer; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Extracts the sub-request callback response. |
||
61 | * |
||
62 | * @return \Drupal\graphql\GraphQL\Buffers\SubRequestResponse |
||
63 | * The sub-request response object. |
||
64 | */ |
||
65 | public function extract() { |
||
66 | $request = $this->requestStack->getCurrentRequest(); |
||
67 | $callback = $request->attributes->get('_graphql_subrequest'); |
||
68 | |||
69 | // TODO: Remove this once https://www.drupal.org/project/drupal/issues/2940036#comment-12479912 is resolved. |
||
70 | $this->languageManager->reset(); |
||
71 | |||
72 | // Collect any potentially leaked cache metadata released by the callback. |
||
73 | $context = new RenderContext(); |
||
74 | $result = $this->renderer->executeInRenderContext($context, function () use ($callback) { |
||
75 | return $callback(); |
||
76 | }); |
||
77 | |||
78 | $response = new SubRequestResponse($result); |
||
79 | if (!$context->isEmpty()) { |
||
80 | $response->addCacheableDependency($context->pop()); |
||
81 | } |
||
82 | |||
83 | return $response; |
||
84 | } |
||
85 | |||
86 | } |
||
87 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths