| 1 | <?php |
||
| 5 | class Config |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * |
||
| 9 | * @var Data |
||
| 10 | */ |
||
| 11 | protected static $data; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Read a path and append its contents to the current configuration. |
||
| 15 | * This method will read a path and append the contents of the path to |
||
| 16 | * the current configuration. The path could either be a directory or a |
||
| 17 | * file. Directories are parsed recursively for config files. First level |
||
| 18 | * sub-directories are used as contexts which can modify some of the |
||
| 19 | * configuration settings in the main directory. |
||
| 20 | * |
||
| 21 | * @param string $path The path to read |
||
| 22 | * @param string $namespace The namespace into which the configuration should be read. |
||
| 23 | */ |
||
| 24 | 4 | public static function readPath($path, $namespace = null) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * |
||
| 31 | * @return Data |
||
| 32 | */ |
||
| 33 | 4 | private static function getData() |
|
| 40 | |||
| 41 | 4 | public static function get($key, $default = null) |
|
| 45 | |||
| 46 | 1 | public static function set($key, $value) |
|
| 50 | |||
| 51 | 1 | public static function setContext($context) |
|
| 55 | |||
| 56 | public static function reset() |
||
| 60 | } |
||
| 61 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: