1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Povs\ListerBundle\Service; |
4
|
|
|
|
5
|
|
|
use Povs\ListerBundle\Declaration\ListInterface; |
6
|
|
|
use Povs\ListerBundle\DependencyInjection\Configuration; |
7
|
|
|
use Povs\ListerBundle\Exception\ListException; |
8
|
|
|
use Symfony\Component\Config\Definition\Processor; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Povilas Margaiatis <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ConfigurationResolver |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
private $defaultConfiguration; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
private $resolvedConfiguration; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* ConfigurationResolver constructor. |
27
|
|
|
* |
28
|
|
|
* @param array $defaultConfiguration |
29
|
|
|
*/ |
30
|
1 |
|
public function __construct(array $defaultConfiguration) |
31
|
|
|
{ |
32
|
1 |
|
$this->defaultConfiguration = $defaultConfiguration; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param ListInterface $list |
37
|
|
|
*/ |
38
|
1 |
|
public function resolve(ListInterface $list): void |
39
|
|
|
{ |
40
|
1 |
|
$configs = $this->defaultConfiguration; |
41
|
|
|
|
42
|
1 |
|
if ($listConfig = $list->configure()) { |
43
|
1 |
|
if (isset($configs[0]['list_config'])) { |
44
|
1 |
|
$listConfig = array_replace_recursive($configs[0]['list_config'], $listConfig); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
$configs[0]['list_config'] = $listConfig; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
$configuration = new Configuration(); |
51
|
1 |
|
$processor = new Processor(); |
52
|
1 |
|
$this->resolvedConfiguration = $processor->processConfiguration($configuration, $configs); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $type type name |
57
|
|
|
* |
58
|
|
|
* @return string fully qualified list type class name |
59
|
|
|
*/ |
60
|
2 |
|
public function getListTypeClass(string $type): string |
61
|
|
|
{ |
62
|
2 |
|
if (!isset($this->resolvedConfiguration['types'][$type])) { |
63
|
1 |
|
throw ListException::listTypeNotConfigured($type); |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
return $this->resolvedConfiguration['types'][$type]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $type |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
2 |
|
public function getTypeConfiguration(string $type): array |
75
|
|
|
{ |
76
|
2 |
|
if (!isset($this->resolvedConfiguration['list_config']['type_configuration'][$type])) { |
77
|
1 |
|
return []; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return $this->resolvedConfiguration['list_config']['type_configuration'][$type] ?? []; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $name param name |
85
|
|
|
* |
86
|
|
|
* @return string|null |
87
|
|
|
*/ |
88
|
1 |
|
public function getRequestConfiguration(string $name): ?string |
89
|
|
|
{ |
90
|
1 |
|
return $this->resolvedConfiguration['list_config']['request'][$name]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
1 |
|
public function getIdentifier(): string |
97
|
|
|
{ |
98
|
1 |
|
return $this->resolvedConfiguration['list_config']['identifier']; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
1 |
|
public function getAlias(): string |
105
|
|
|
{ |
106
|
1 |
|
return $this->resolvedConfiguration['list_config']['alias']; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return bool |
111
|
|
|
*/ |
112
|
1 |
|
public function getTranslate(): bool |
113
|
|
|
{ |
114
|
1 |
|
return $this->resolvedConfiguration['list_config']['translate']; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string|null |
119
|
|
|
*/ |
120
|
1 |
|
public function getTranslationDomain(): ?string |
121
|
|
|
{ |
122
|
1 |
|
return $this->resolvedConfiguration['list_config']['translation_domain']; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return array |
127
|
|
|
*/ |
128
|
1 |
|
public function getFormConfiguration(): array |
129
|
|
|
{ |
130
|
1 |
|
return $this->resolvedConfiguration['list_config']['form_configuration']; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
1 |
|
public function isMultiColumnSortable(): bool |
137
|
|
|
{ |
138
|
1 |
|
return $this->resolvedConfiguration['list_config']['multi_column_sort']; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|