1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2020 Enjoys. |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
declare(strict_types=1); |
28
|
|
|
|
29
|
|
|
namespace Enjoys\Config; |
30
|
|
|
|
31
|
|
|
use Enjoys\Traits\Options; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Description of Parse |
35
|
|
|
* |
36
|
|
|
* @author Enjoys |
37
|
|
|
*/ |
38
|
|
|
abstract class Parse implements ParseInterface, \Psr\Log\LoggerAwareInterface |
39
|
|
|
{ |
40
|
|
|
use Options; |
41
|
|
|
use \Psr\Log\LoggerAwareTrait; |
42
|
|
|
|
43
|
|
|
private string $configSource; |
44
|
|
|
// protected ?array $errors = null; |
45
|
11 |
|
|
46
|
|
|
public function __construct(string $config) |
47
|
11 |
|
{ |
48
|
11 |
|
$this->configSource = $config; |
49
|
|
|
} |
50
|
11 |
|
|
51
|
|
|
public function parse() |
52
|
11 |
|
{ |
53
|
6 |
|
if (!is_file($this->configSource)) { |
54
|
|
|
return $this->parseString($this->configSource); |
55
|
|
|
} |
56
|
5 |
|
|
57
|
|
|
return $this->parseFile($this->configSource); |
58
|
|
|
} |
59
|
2 |
|
|
60
|
|
|
|
61
|
2 |
|
|
62
|
2 |
|
// protected function setError(string $error): void |
63
|
|
|
// { |
64
|
3 |
|
// $this->errors[] = $error; |
65
|
|
|
// } |
66
|
3 |
|
|
67
|
|
|
// public function getErrors(): ?array |
68
|
|
|
// { |
69
|
|
|
// return $this->errors; |
70
|
|
|
// } |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
abstract protected function parseString(string $string); |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
|
|
abstract protected function parseFile(string $filename); |
81
|
|
|
} |
82
|
|
|
|