1 | <?php |
||
21 | abstract class File |
||
22 | { |
||
23 | /** |
||
24 | * Path to config file |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $filename; |
||
29 | |||
30 | /** |
||
31 | * Path to config file |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $adapters; |
||
36 | |||
37 | /** |
||
38 | * Handling the bootstrapping |
||
39 | * |
||
40 | * @var \phpbu\App\Configuration\Bootstrapper |
||
41 | */ |
||
42 | protected $bootstrapper; |
||
43 | |||
44 | /** |
||
45 | * List of validation errors |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $errors = []; |
||
50 | |||
51 | /** |
||
52 | * File constructor |
||
53 | * |
||
54 | * @param string $file |
||
55 | * @param \phpbu\App\Configuration\Bootstrapper $bootstrapper |
||
56 | */ |
||
57 | 39 | public function __construct(string $file, Configuration\Bootstrapper $bootstrapper) |
|
62 | |||
63 | /** |
||
64 | * Is the configuration valid |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | 1 | public function hasValidationErrors(): bool |
|
69 | { |
||
70 | 1 | return \count($this->errors) > 0; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Return a list of all validation errors |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | 1 | public function getValidationErrors(): array |
|
79 | { |
||
80 | 1 | return $this->errors; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Returns the phpbu Configuration |
||
85 | * |
||
86 | * @param \phpbu\App\Factory $factory |
||
87 | * @return \phpbu\App\Configuration |
||
88 | * @throws \phpbu\App\Exception |
||
89 | */ |
||
90 | 33 | public function getConfiguration(AppFactory $factory) : Configuration |
|
105 | |||
106 | /** |
||
107 | * Load all available config adapters |
||
108 | * |
||
109 | * @param \phpbu\App\Factory $factory |
||
110 | * @throws \phpbu\App\Exception |
||
111 | */ |
||
112 | 33 | protected function setupAdapters(AppFactory $factory) |
|
118 | |||
119 | /** |
||
120 | * Return a registered adapter |
||
121 | * |
||
122 | * @param string $name |
||
123 | * @return \phpbu\App\Adapter |
||
124 | * @throws \phpbu\App\Exception |
||
125 | */ |
||
126 | 4 | protected function getAdapter($name) |
|
133 | |||
134 | /** |
||
135 | * Return list of adapter configs |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | abstract protected function getAdapterConfigs(); |
||
140 | |||
141 | /** |
||
142 | * Set the phpbu application settings |
||
143 | * |
||
144 | * @param \phpbu\App\Configuration $configuration |
||
145 | */ |
||
146 | abstract public function setAppSettings(Configuration $configuration); |
||
147 | |||
148 | /** |
||
149 | * Set the log configuration |
||
150 | * |
||
151 | * @param \phpbu\App\Configuration $configuration |
||
152 | * @throws \phpbu\App\Exception |
||
153 | */ |
||
154 | abstract public function setLoggers(Configuration $configuration); |
||
155 | |||
156 | /** |
||
157 | * Set the backup configurations |
||
158 | * |
||
159 | * @param \phpbu\App\Configuration $configuration |
||
160 | * @throws \phpbu\App\Exception |
||
161 | */ |
||
162 | abstract public function setBackups(Configuration $configuration); |
||
163 | |||
164 | /** |
||
165 | * Handles the bootstrap file inclusion |
||
166 | * |
||
167 | * @param \phpbu\App\Configuration $configuration |
||
168 | * @throws \phpbu\App\Exception |
||
169 | */ |
||
170 | 33 | protected function handleBootstrap(Configuration $configuration) |
|
174 | |||
175 | /** |
||
176 | * Converts a path to an absolute one if necessary |
||
177 | * |
||
178 | * @param string $path |
||
179 | * @param boolean $useIncludePath |
||
180 | * @return string |
||
181 | */ |
||
182 | 32 | protected function toAbsolutePath($path, $useIncludePath = false) |
|
186 | |||
187 | /** |
||
188 | * Return option value |
||
189 | * Checks if the value should be fetched from an Adapter, if not it just returns the value. |
||
190 | * |
||
191 | * @param string $value |
||
192 | * @return string |
||
193 | * @throws \phpbu\App\Exception |
||
194 | */ |
||
195 | 29 | protected function getAdapterizedValue($value) |
|
206 | |||
207 | /** |
||
208 | * Load the file |
||
209 | * |
||
210 | * @param string $filename |
||
211 | * @throws \phpbu\App\Exception |
||
212 | * @return \stdClass |
||
213 | */ |
||
214 | 39 | protected function loadFile($filename) |
|
225 | } |
||
226 |