1 | <?php |
||
14 | class AbstractFileParser implements FileParserInterface |
||
|
|||
15 | { |
||
16 | /** |
||
17 | * Configuration file |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $file = null; |
||
22 | |||
23 | /** |
||
24 | * The configuration variables |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $vars = []; |
||
29 | |||
30 | /** |
||
31 | * Sets up the file to be parsed and variables |
||
32 | * |
||
33 | * @param string $file Config file name |
||
34 | * @param array $vars Variables to parse in the file |
||
35 | * @return void |
||
36 | */ |
||
37 | public function __construct($file = null, $vars = []) |
||
43 | |||
44 | public function load($overwrite = false, $cache = true) |
||
48 | |||
49 | public function parse($file) |
||
53 | |||
54 | public function save($contents) |
||
58 | |||
59 | /** |
||
60 | * Gets the default group name. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function group() |
||
68 | |||
69 | public function getSupportedFileExtensions() |
||
73 | |||
74 | #: Protected Methods |
||
75 | |||
76 | /** |
||
77 | * Finds the given config files |
||
78 | * |
||
79 | * @param bool $cache |
||
80 | * param bool $multiple Whether to load multiple files or not |
||
81 | * @return array |
||
82 | */ |
||
83 | protected function findFile($cache = true) |
||
87 | |||
88 | /** |
||
89 | * Parses a string using all of the previously set variables. |
||
90 | * Allows you to use something like %ENV% in non-PHP files. |
||
91 | * |
||
92 | * @param string $string String to parse |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function parseVars($string) |
||
103 | |||
104 | /** |
||
105 | * Replaces given constants to their string counterparts. |
||
106 | * |
||
107 | * @param array $array Array to be prepped |
||
108 | * @return array Prepped array |
||
109 | */ |
||
110 | protected function prepVars(&$array) |
||
132 | |||
133 | #: Abstract Methods |
||
134 | |||
135 | /** |
||
136 | * Must be implemented by child class. |
||
137 | * Gets called for each file to load. |
||
138 | */ |
||
139 | abstract protected function loadFile($file); |
||
140 | |||
141 | /** |
||
142 | * Must be impletmented by child class. |
||
143 | * Gets called when saving a configuration file. |
||
144 | * |
||
145 | * @param array $contents config array to save |
||
146 | * @return string formatted output |
||
147 | */ |
||
148 | abstract protected function exportFormat($contents); |
||
149 | } |
||
150 | |||
152 |