1 | <?php |
||
19 | final class Konfig extends AbstractKonfig |
||
20 | { |
||
21 | /** |
||
22 | * @var SplStack |
||
23 | * @since 0.1 |
||
24 | */ |
||
25 | protected $fileParsers; |
||
26 | |||
27 | /** |
||
28 | * Stores loaded configuration files |
||
29 | * |
||
30 | * @var array $loadedFiles Array of loaded configuration files |
||
31 | */ |
||
32 | static $loadedFiles = []; |
||
33 | |||
34 | /** |
||
35 | * Loads a supported configuration file format. |
||
36 | * |
||
37 | * @param string|array|mixed $path String file | configuration array | Konfig instance |
||
38 | * @throws EmptyDirectoryException If `$path` is an empty directory |
||
39 | */ |
||
40 | public function __construct($path, array $parsers = []) |
||
63 | |||
64 | /** |
||
65 | * Static method for loading a Konfig instance. |
||
66 | * |
||
67 | * @param string|array|mixed $path string file | configuration array | Konfig instance |
||
68 | * @return Konfig |
||
69 | */ |
||
70 | public static function load($path = null) |
||
74 | |||
75 | /** |
||
76 | * Static method for getting loaded Konfig files. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public static function loaded() |
||
84 | |||
85 | /** |
||
86 | * @return FileParser[] |
||
87 | * @since 0.1 |
||
88 | */ |
||
89 | public function getFileParsers() |
||
93 | |||
94 | /** |
||
95 | * @return void |
||
96 | * @since 0.1 |
||
97 | */ |
||
98 | protected function addFileParser(FileParser $fileParser) |
||
102 | |||
103 | /** |
||
104 | * @return void |
||
105 | * @since 0.1 |
||
106 | */ |
||
107 | protected function setFileParsers(array $fileParsers = []) |
||
122 | |||
123 | /** |
||
124 | * Gets a parser for a given file extension |
||
125 | * |
||
126 | * @param string $ext |
||
127 | * @return Konfig\FileParser |
||
128 | * @throws UnsupportedFileFormatException If `$path` is an unsupported file format |
||
129 | */ |
||
130 | private function getParser($ext) |
||
154 | |||
155 | /** |
||
156 | * Checks `$path` to see if it is either an array, a directory, or a file |
||
157 | * |
||
158 | * @param string | array $path |
||
159 | * @return array |
||
160 | * @throws EmptyDirectoryException If `$path` is an empty directory |
||
161 | * @throws FileNotFoundException If a file is not found at `$path` |
||
162 | */ |
||
163 | private function getValidPath($path = null) |
||
224 | |||
225 | public function __toString() |
||
229 | } |
||
230 | |||
232 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.