1 | <?php |
||
32 | abstract class AbstractFileParser implements FileParser |
||
33 | { |
||
34 | /** |
||
35 | * Configuration file. |
||
36 | * |
||
37 | * @var string $file |
||
38 | * |
||
39 | * @since 0.1.0 |
||
40 | */ |
||
41 | protected $file; |
||
42 | |||
43 | /** |
||
44 | * The configuration variables. |
||
45 | * |
||
46 | * @var array $variables |
||
47 | * |
||
48 | * @since 0.1.0 |
||
49 | */ |
||
50 | protected $variables = []; |
||
51 | |||
52 | // PROTECTED METHODS |
||
53 | |||
54 | /** |
||
55 | * Parses a string using all of the previously set variables. |
||
56 | * Allows you to use something like %ENV% in non-PHP files. |
||
57 | * |
||
58 | * @param string $string String to parse |
||
59 | * |
||
60 | * @return string |
||
61 | * @since 0.1.0 |
||
62 | * @codeCoverageIgnore |
||
63 | */ |
||
64 | protected function parseVars($string = null) |
||
72 | |||
73 | /** |
||
74 | * Replaces given constants to their string counterparts. |
||
75 | * |
||
76 | * @param array $array Array to be prepped |
||
77 | * |
||
78 | * @return array Prepped array |
||
79 | * @since 0.1.0 |
||
80 | * @codeCoverageIgnore |
||
81 | */ |
||
82 | protected function prepVars(array &$array) |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | * |
||
111 | * @param string $file File path |
||
112 | * |
||
113 | * @return array The parsed data |
||
114 | * |
||
115 | * @since 0.1.0 |
||
116 | */ |
||
117 | abstract public function parse($file); |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | * |
||
122 | * @return array Supported extensions |
||
123 | * |
||
124 | * @since 0.1.0 |
||
125 | */ |
||
126 | abstract public function getSupportedFileExtensions(); |
||
127 | |||
128 | /** |
||
129 | * Must be implemented by child class. Gets called for each file to load. |
||
130 | * |
||
131 | * @param string $file File path |
||
132 | * |
||
133 | * @return array The parsed file data |
||
134 | * |
||
135 | * @since 0.2.4 |
||
136 | * @codeCoverageIgnore |
||
137 | */ |
||
138 | abstract protected function loadFile($file = null); |
||
139 | |||
140 | /** |
||
141 | * Must be impletmented by child class. Gets called when saving a config file. |
||
142 | * |
||
143 | * @param array $contents config array to save |
||
144 | * |
||
145 | * @return string formatted output |
||
146 | * |
||
147 | * @since 0.2.4 |
||
148 | * @codeCoverageIgnore |
||
149 | */ |
||
150 | abstract protected function exportFormat($contents = null); |
||
151 | |||
152 | /** |
||
153 | * Gets the default group name. |
||
154 | * |
||
155 | * @return string |
||
156 | * |
||
157 | * @since 0.2.4 |
||
158 | * @codeCoverageIgnore |
||
159 | */ |
||
160 | public function group() |
||
164 | |||
165 | /** |
||
166 | * __toString. |
||
167 | * |
||
168 | * @return string |
||
169 | * @since 0.1.2 |
||
170 | * @codeCoverageIgnore |
||
171 | */ |
||
172 | public function __toString() |
||
176 | } |
||
177 | |||
179 |