1 | <?php |
||
7 | abstract class AbstractReader implements Configuration |
||
8 | { |
||
9 | protected |
||
10 | $defaultEnvironment; |
||
11 | |||
12 | private |
||
13 | $overridenVariables, |
||
|
|||
14 | $customData; |
||
15 | |||
16 | public function __construct() |
||
22 | |||
23 | public function read($variable, $environment = null) |
||
24 | { |
||
25 | $value = null; |
||
26 | |||
27 | if(array_key_exists($variable, $this->overridenVariables)) |
||
28 | { |
||
29 | $value = $this->overridenVariables[$variable]; |
||
30 | } |
||
31 | else |
||
32 | { |
||
33 | $value = $this->readRaw($variable, $environment); |
||
34 | } |
||
35 | |||
36 | return $this->handleCustomData($value); |
||
37 | } |
||
38 | |||
39 | abstract protected function readRaw($variable, $environment = null); |
||
40 | |||
41 | public function setDefaultEnvironment($environment) |
||
50 | |||
51 | public function getAllValuesForEnvironment($environment = null) |
||
52 | { |
||
53 | $result = array(); |
||
54 | |||
55 | $variables = $this->getAllVariables(); |
||
56 | |||
57 | foreach($variables as $variable) |
||
58 | { |
||
59 | try |
||
60 | { |
||
61 | $value = $this->read($variable, $environment); |
||
62 | } |
||
63 | catch(\RuntimeException $e) |
||
64 | { |
||
65 | $value = Configuration::NOT_FOUND; |
||
66 | } |
||
67 | |||
68 | $result[$variable] = $value; |
||
69 | } |
||
70 | |||
71 | return $result; |
||
72 | } |
||
73 | |||
74 | public function overrideVariable($variable, $value) |
||
80 | |||
81 | public function setCustomData($customDataName, $value) |
||
88 | |||
89 | private function handleCustomData($value) |
||
98 | } |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.