1 | <?php |
||
2 | |||
3 | namespace Drupal\graphql\Plugin; |
||
4 | |||
5 | use Drupal\Core\Cache\Cache; |
||
0 ignored issues
–
show
|
|||
6 | use Drupal\Core\Cache\CacheBackendInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Cache\CacheBackendInterface 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\Extension\ModuleHandlerInterface; |
||
0 ignored issues
–
show
The type
Drupal\Core\Extension\ModuleHandlerInterface 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\Plugin\DefaultPluginManager; |
||
0 ignored issues
–
show
The type
Drupal\Core\Plugin\DefaultPluginManager 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 | |||
10 | class FieldPluginManager extends DefaultPluginManager { |
||
11 | |||
12 | /** |
||
13 | * Static cache of plugin instances. |
||
14 | * |
||
15 | * @var \Drupal\graphql\Plugin\FieldPluginInterface[] |
||
16 | */ |
||
17 | protected $instances; |
||
18 | |||
19 | /** |
||
20 | * FieldPluginManager constructor. |
||
21 | * |
||
22 | * @param bool|string $pluginSubdirectory |
||
23 | * The plugin's subdirectory. |
||
24 | * @param \Traversable $namespaces |
||
25 | * An object that implements \Traversable which contains the root paths |
||
26 | * keyed by the corresponding namespace to look for plugin implementations. |
||
27 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler |
||
28 | * The module handler. |
||
29 | * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend |
||
30 | * The cache backend. |
||
31 | * @param string|null $pluginInterface |
||
32 | * The interface each plugin should implement. |
||
33 | * @param string $pluginAnnotationName |
||
34 | * The name of the annotation that contains the plugin definition. |
||
35 | * @param array $config |
||
36 | * The configuration service parameter. |
||
37 | */ |
||
38 | public function __construct( |
||
39 | $pluginSubdirectory, |
||
40 | \Traversable $namespaces, |
||
41 | ModuleHandlerInterface $moduleHandler, |
||
42 | CacheBackendInterface $cacheBackend, |
||
43 | $pluginInterface, |
||
44 | $pluginAnnotationName, |
||
45 | array $config |
||
46 | ) { |
||
47 | parent::__construct( |
||
48 | $pluginSubdirectory, |
||
49 | $namespaces, |
||
50 | $moduleHandler, |
||
51 | $pluginInterface, |
||
52 | $pluginAnnotationName |
||
53 | ); |
||
54 | |||
55 | $this->alterInfo('graphql_fields'); |
||
56 | $this->useCaches(empty($config['development'])); |
||
57 | $this->setCacheBackend($cacheBackend, 'fields', ['graphql']); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function getInstance(array $options) { |
||
64 | if (!isset($this->instances[$options['id']])) { |
||
65 | $this->instances[$options['id']] = $this->createInstance($options['id']); |
||
66 | } |
||
67 | |||
68 | return $this->instances[$options['id']]; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function clearCachedDefinitions() { |
||
75 | parent::clearCachedDefinitions(); |
||
76 | $this->instances = []; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | protected function setCachedDefinitions($definitions) { |
||
83 | $this->definitions = $definitions; |
||
0 ignored issues
–
show
|
|||
84 | $this->cacheSet($this->cacheKey, $definitions, $this->getCacheMaxAge(), $this->getCacheTags()); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function getCacheTags() { |
||
91 | $definitions = $this->getDefinitions(); |
||
92 | return array_reduce($definitions, function ($carry, $current) { |
||
93 | if (!empty($current['schema_cache_tags'])) { |
||
94 | return Cache::mergeTags($carry, $current['schema_cache_tags']); |
||
95 | } |
||
96 | |||
97 | return $carry; |
||
98 | }, $this->cacheTags); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function getCacheMaxAge() { |
||
105 | $definitions = $this->getDefinitions(); |
||
106 | $age = Cache::PERMANENT; |
||
107 | foreach ($definitions as $definition) { |
||
108 | if (!isset($definition['schema_cache_max_age'])) { |
||
109 | continue; |
||
110 | } |
||
111 | |||
112 | // Bail out early if the cache max age is 0. |
||
113 | if (($age = Cache::mergeMaxAges($age, $definition['schema_cache_max_age'])) === 0) { |
||
114 | return $age; |
||
115 | } |
||
116 | } |
||
117 | |||
118 | return $age; |
||
119 | } |
||
120 | } |
||
121 |
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