1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\EntityBundle\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\QueryBuilder; |
6
|
|
|
|
7
|
|
|
class ChainDictionaryValueListProvider |
8
|
|
|
{ |
9
|
|
|
/** @var array */ |
10
|
|
|
private $providers; |
11
|
|
|
|
12
|
|
|
/** @var DictionaryValueListProviderInterface[] */ |
13
|
|
|
private $sorted; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Registers the provider in the chain. |
17
|
|
|
* |
18
|
|
|
* @param DictionaryValueListProviderInterface $provider |
19
|
|
|
* @param int $priority |
20
|
|
|
*/ |
21
|
|
|
public function addProvider(DictionaryValueListProviderInterface $provider, $priority = 0) |
22
|
|
|
{ |
23
|
|
|
$this->providers[$priority][] = $provider; |
24
|
|
|
$this->sorted = null; |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Returns the registered providers sorted by priority. |
29
|
|
|
* |
30
|
|
|
* @return DictionaryValueListProviderInterface[] |
31
|
|
|
*/ |
32
|
|
|
protected function getProviders() |
33
|
|
|
{ |
34
|
|
|
if (null === $this->sorted) { |
35
|
|
|
if (empty($this->providers)) { |
36
|
|
|
$this->sorted = []; |
37
|
|
|
} else { |
38
|
|
|
krsort($this->providers); |
39
|
|
|
$this->sorted = call_user_func_array('array_merge', $this->providers); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $this->sorted; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns the configuration of the entity serializer for a given dictionary class |
48
|
|
|
* |
49
|
|
|
* @param string $className The FQCN of a dictionary entity |
50
|
|
|
* |
51
|
|
|
* @return array|null |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function getSerializationConfig($className) |
54
|
|
|
{ |
55
|
|
|
if (null === $className) { |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$providers = $this->getProviders(); |
60
|
|
|
foreach ($providers as $provider) { |
61
|
|
|
if ($provider->supports($className)) { |
62
|
|
|
return $provider->getSerializationConfig($className); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets a query builder for getting dictionary item values for a given dictionary class |
71
|
|
|
* |
72
|
|
|
* @param string $className The FQCN of a dictionary entity |
73
|
|
|
* |
74
|
|
|
* @return QueryBuilder|null |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function getValueListQueryBuilder($className) |
77
|
|
|
{ |
78
|
|
|
if (null === $className) { |
79
|
|
|
return null; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$providers = $this->getProviders(); |
83
|
|
|
foreach ($providers as $provider) { |
84
|
|
|
if ($provider->supports($className)) { |
85
|
|
|
return $provider->getValueListQueryBuilder($className); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return null; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Gets a list of supported entity classes |
94
|
|
|
* |
95
|
|
|
* @return string[] |
96
|
|
|
*/ |
97
|
|
|
public function getSupportedEntityClasses() |
98
|
|
|
{ |
99
|
|
|
$supportedClasses = []; |
100
|
|
|
|
101
|
|
|
$providers = $this->getProviders(); |
102
|
|
|
foreach ($providers as $provider) { |
103
|
|
|
$supportedClasses = array_merge($supportedClasses, $provider->getSupportedEntityClasses()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return array_unique($supportedClasses); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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..