1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\graphql\QueryProvider; |
4
|
|
|
|
5
|
|
|
class QueryProvider implements QueryProviderInterface { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Unsorted list of query providers nested and keyed by priority. |
9
|
|
|
* |
10
|
|
|
* @var \Drupal\graphql\QueryProvider\QueryProviderInterface[] |
11
|
|
|
*/ |
12
|
|
|
protected $providers = []; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Sorted list of query providers. |
16
|
|
|
* |
17
|
|
|
* @var \Drupal\graphql\QueryProvider\QueryProviderInterface[] |
18
|
|
|
*/ |
19
|
|
|
protected $sortedProviders; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function getQuery(array $params) { |
25
|
|
|
foreach ($this->getSortedProviders() as $provider) { |
26
|
|
|
if ($query = $provider->getQuery($params)) { |
27
|
|
|
return $query; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return NULL; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Adds a query provider. |
36
|
|
|
* |
37
|
|
|
* @param \Drupal\graphql\QueryProvider\QueryProviderInterface $provider |
38
|
|
|
* The query provider to add. |
39
|
|
|
* @param int $priority |
40
|
|
|
* Priority of the query provider. |
41
|
|
|
*/ |
42
|
|
|
public function addQueryProvider(QueryProviderInterface $provider, $priority = 0) { |
43
|
|
|
$this->providers[$priority][] = $provider; |
44
|
|
|
$this->sortedProviders = NULL; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns the sorted array of query providers. |
49
|
|
|
* |
50
|
|
|
* @return \Drupal\graphql\QueryProvider\QueryProviderInterface[] |
51
|
|
|
* An array of query provider objects. |
52
|
|
|
*/ |
53
|
|
|
protected function getSortedProviders() { |
54
|
|
|
if (!isset($this->sortedProviders)) { |
55
|
|
|
krsort($this->providers); |
56
|
|
|
|
57
|
|
|
$this->sortedProviders = []; |
58
|
|
|
foreach ($this->providers as $providers) { |
59
|
|
|
$this->sortedProviders = array_merge($this->sortedProviders, $providers); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->sortedProviders; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..