1 | <?php |
||
7 | abstract class ConfigurationContainer |
||
8 | { |
||
9 | /** |
||
10 | * @var string The name of the element |
||
11 | */ |
||
12 | protected $name; |
||
13 | |||
14 | /** |
||
15 | * @var array The data for this container |
||
16 | */ |
||
17 | protected $data; |
||
18 | |||
19 | /** |
||
20 | * @var \Onigoetz\Deployer\Configuration\ConfigurationManager |
||
21 | */ |
||
22 | protected $manager; |
||
23 | |||
24 | 237 | public function __construct($name, array $data, ConfigurationManager $manager) |
|
30 | |||
31 | 69 | public function getName() |
|
35 | |||
36 | /** |
||
37 | * Get the configuration manager's key |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 51 | public function getContainerType() |
|
45 | |||
46 | /** |
||
47 | * Get the value or throw an exception |
||
48 | * |
||
49 | * @param string $key |
||
50 | * @param $errorMessage |
||
51 | * @throws \LogicException |
||
52 | * @return mixed |
||
53 | */ |
||
54 | 48 | protected function getValueOrFail($key, $errorMessage) |
|
55 | { |
||
56 | 48 | if (array_key_exists($key, $this->data)) { |
|
57 | 39 | return $this->data[$key]; |
|
58 | } |
||
59 | |||
60 | 15 | throw new \LogicException($errorMessage); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Get the value or return the default |
||
65 | * |
||
66 | * @param string $key |
||
67 | * @param $default |
||
68 | * @return mixed |
||
69 | */ |
||
70 | 18 | protected function getValueOrDefault($key, $default) |
|
78 | |||
79 | /** |
||
80 | * Tests validity |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | 57 | public function isValid() |
|
94 | |||
95 | /** |
||
96 | * Internal validity check |
||
97 | * |
||
98 | * @throws \LogicException |
||
99 | * @return bool |
||
100 | */ |
||
101 | abstract public function checkValidity(); |
||
102 | } |
||
103 |