1 | <?php |
||
17 | class SettingsCollection implements CollectionInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var StorageAdapterInterface |
||
21 | */ |
||
22 | protected $adapter; |
||
23 | |||
24 | /** |
||
25 | * @var OwnerProviderInterface |
||
26 | */ |
||
27 | protected $ownerProvider; |
||
28 | |||
29 | /** |
||
30 | * @var CollectionOptionsInterface |
||
31 | */ |
||
32 | protected $options; |
||
33 | |||
34 | /** |
||
35 | * @var TypesManager |
||
36 | */ |
||
37 | protected $typesManager; |
||
38 | |||
39 | /** |
||
40 | * @param CollectionOptionsInterface $options |
||
41 | * @param StorageAdapterInterface $adapter |
||
42 | * @param OwnerProviderInterface $owner_provider |
||
43 | * @param TypesManager $typesManager |
||
44 | */ |
||
45 | 13 | public function __construct( |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 3 | public function setValue($name, $value) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 5 | public function getValue($name) |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 2 | public function getList() |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 4 | public function isValid($name, $value) |
|
119 | { |
||
120 | 4 | $setting = $this->getSettingOptions($name); |
|
121 | |||
122 | 3 | if (!isset($setting['type'])) { |
|
123 | 1 | throw new RuntimeException('Missing "type" option in setting configuration'); |
|
124 | } |
||
125 | |||
126 | 2 | if (!$this->typesManager->has($setting['type'])) { |
|
127 | 1 | throw new RuntimeException(sprintf( |
|
128 | 1 | "SettingType '%s' does not exist", |
|
129 | 1 | is_string($setting['type']) ? $setting['type'] : gettype($setting['type']) |
|
130 | 1 | )); |
|
131 | } |
||
132 | |||
133 | 1 | $type = $this->typesManager->get($setting['type']); |
|
134 | |||
135 | if (!empty($setting['options']) && is_array($setting)) { |
||
136 | $type->setOptions($setting['options']); |
||
137 | } |
||
138 | |||
139 | return $type->isValid($value); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | 11 | public function getOptions() |
|
149 | |||
150 | /** |
||
151 | * @param $name |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | 11 | private function getSettingOptions($name) |
|
177 | } |
||
178 |