1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Common\Manager; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class OptionsManager |
7
|
|
|
* |
8
|
|
|
* @package Box\Spout\Common\Manager |
9
|
|
|
*/ |
10
|
|
|
abstract class OptionsManagerAbstract implements OptionsManagerInterface |
11
|
|
|
{ |
12
|
|
|
const PREFIX_OPTION = 'OPTION_'; |
13
|
|
|
|
14
|
|
|
/** @var string[] List of all supported option names */ |
15
|
|
|
private $supportedOptions = []; |
16
|
|
|
|
17
|
|
|
/** @var array Associative array [OPTION_NAME => OPTION_VALUE] */ |
18
|
|
|
private $options = []; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* OptionsManagerAbstract constructor. |
22
|
|
|
*/ |
23
|
219 |
|
public function __construct() |
24
|
|
|
{ |
25
|
219 |
|
$this->supportedOptions = $this->getSupportedOptions(); |
26
|
219 |
|
$this->setDefaultOptions(); |
27
|
219 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return array List of supported options |
31
|
|
|
*/ |
32
|
|
|
abstract protected function getSupportedOptions(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Sets the default options. |
36
|
|
|
* To be overriden by child classes |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
abstract protected function setDefaultOptions(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets the given option, if this option is supported. |
44
|
|
|
* |
45
|
|
|
* @param string $optionName |
46
|
|
|
* @param mixed $optionValue |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
219 |
|
public function setOption($optionName, $optionValue) |
50
|
|
|
{ |
51
|
219 |
|
if (in_array($optionName, $this->supportedOptions)) { |
52
|
219 |
|
$this->options[$optionName] = $optionValue; |
53
|
|
|
} |
54
|
219 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $optionName |
58
|
|
|
* @return mixed|null The set option or NULL if no option with given name found |
59
|
|
|
*/ |
60
|
205 |
|
public function getOption($optionName) |
61
|
|
|
{ |
62
|
205 |
|
$optionValue = null; |
63
|
|
|
|
64
|
205 |
|
if (isset($this->options[$optionName])) { |
65
|
199 |
|
$optionValue = $this->options[$optionName]; |
66
|
|
|
} |
67
|
|
|
|
68
|
205 |
|
return $optionValue; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|