| 1 | <?php |
||
| 28 | abstract class AbstractConfig extends ArrayObject implements ConfigInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Array of strings that are used as delimiters to parse configuration keys. |
||
| 33 | * |
||
| 34 | * @since 0.1.6 |
||
| 35 | * |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | protected $delimiter = ['\\', '/', '.']; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Instantiate the AbstractConfig object. |
||
| 42 | * |
||
| 43 | * @since 0.1.0 |
||
| 44 | * @since 0.1.6 Accepts a delimiter to parse configuration keys. |
||
| 45 | * |
||
| 46 | * @param array $config Array with settings. |
||
| 47 | * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse |
||
| 48 | * configuration keys. Defaults to "\", "/" & ".". |
||
| 49 | */ |
||
| 50 | 3 | public function __construct(array $config, $delimiter = null) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Get the value of a specific key. |
||
| 62 | * |
||
| 63 | * To get a value several levels deep, add the keys for each level as a comma-separated list. |
||
| 64 | * |
||
| 65 | * @since 0.1.0 |
||
| 66 | * @since 0.1.4 Accepts list of keys. |
||
| 67 | * |
||
| 68 | * @param string ... List of keys. |
||
| 69 | * @return mixed |
||
| 70 | * @throws BadMethodCallException If no argument was provided. |
||
| 71 | * @throws OutOfRangeException If an unknown key is requested. |
||
| 72 | */ |
||
| 73 | 3 | public function getKey() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Check whether the Config has a specific key. |
||
| 89 | * |
||
| 90 | * To check a value several levels deep, add the keys for each level as a comma-separated list. |
||
| 91 | * |
||
| 92 | * @since 0.1.0 |
||
| 93 | * @since 0.1.4 Accepts list of keys. |
||
| 94 | * |
||
| 95 | * @param string ... List of keys. |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | 3 | public function hasKey() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Get a (multi-dimensional) array of all the configuration settings. |
||
| 120 | * |
||
| 121 | * @since 0.1.4 |
||
| 122 | * |
||
| 123 | * @return array |
||
| 124 | */ |
||
| 125 | 1 | public function getAll() |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Get the an array with all the keys |
||
| 132 | * |
||
| 133 | * @since 0.1.0 |
||
| 134 | * @return array |
||
|
|
|||
| 135 | */ |
||
| 136 | 1 | public function getKeys() |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Get a new config at a specific sub-level. |
||
| 143 | * |
||
| 144 | * @since 0.1.13 |
||
| 145 | * |
||
| 146 | * @param string ... List of keys. |
||
| 147 | * @return ConfigInterface |
||
|
1 ignored issue
–
show
|
|||
| 148 | * @throws BadMethodCallException If no argument was provided. |
||
| 149 | * @throws OutOfRangeException If an unknown key is requested. |
||
| 150 | */ |
||
| 151 | 1 | public function getSubConfig() |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Validate a set of keys to make sure they exist. |
||
| 163 | * |
||
| 164 | * @since 0.1.13 |
||
| 165 | * |
||
| 166 | * @param string ... List of keys. |
||
| 167 | * @return array List of keys. |
||
| 168 | * @throws BadMethodCallException If no argument was provided. |
||
| 169 | * @throws OutOfRangeException If an unknown key is requested. |
||
| 170 | */ |
||
| 171 | 1 | public function validateKeys() |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Reduce the currently stored config array to a subarray at a specific level. |
||
| 191 | * |
||
| 192 | * @since 0.1.13 |
||
| 193 | * |
||
| 194 | * @param array $keys Array of keys that point to a key down in the hierarchy. |
||
| 195 | */ |
||
| 196 | 1 | protected function reduceToSubkey(array $keys) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Recursively extract the configuration key arguments from an arbitrary array. |
||
| 203 | * |
||
| 204 | * @since 0.1.6 |
||
| 205 | * |
||
| 206 | * @param array $arguments Array as fetched through get_func_args(). |
||
| 207 | * @return array Array of strings. |
||
| 208 | * @throws BadMethodCallException If no argument was provided. |
||
| 209 | */ |
||
| 210 | 5 | protected function getKeyArguments($arguments) |
|
| 226 | |||
| 227 | /** |
||
| 228 | * Extract individual keys from a delimited string. |
||
| 229 | * |
||
| 230 | * @since 0.1.6 |
||
| 231 | * |
||
| 232 | * @param string $keyString Delimited string of keys. |
||
| 233 | * @return array Array of key strings. |
||
| 234 | */ |
||
| 235 | 2 | protected function parseKeysString($keyString) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Validate the Config file. |
||
| 247 | * |
||
| 248 | * @since 0.1.0 |
||
| 249 | * @return boolean |
||
| 250 | */ |
||
| 251 | abstract public function isValid(); |
||
| 252 | } |
||
| 253 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.