1 | <?php |
||
30 | class ResourceProvider extends AbstractResource |
||
31 | { |
||
32 | use ResourceFlagsTrait; |
||
33 | |||
34 | /** |
||
35 | * The configuration entity -- could be a file, array or dir |
||
36 | * |
||
37 | * @var array|string |
||
38 | */ |
||
39 | private $entity; |
||
40 | |||
41 | /** |
||
42 | * If the import was not relative then the content will be stored in this array |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $parent_content = array(); |
||
47 | |||
48 | /** |
||
49 | * Are dirs wanting to be recursively searched |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | private $recursive; |
||
54 | |||
55 | /** |
||
56 | * Is the import relative |
||
57 | * |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $relative; |
||
61 | |||
62 | /** |
||
63 | * Suppress file not found exceptions |
||
64 | * |
||
65 | * @var bool |
||
66 | */ |
||
67 | private $suppress_file_exceptions = false; |
||
68 | |||
69 | /** |
||
70 | * The parent Vars class |
||
71 | * |
||
72 | * @var \M1\Vars\Vars |
||
73 | */ |
||
74 | public $vars; |
||
75 | |||
76 | /** |
||
77 | * The ResourceProvider constructor creates the content from the entity |
||
78 | * |
||
79 | * @param \M1\Vars\Vars $vars The calling Vars class |
||
80 | * @param string|array $entity The configuration entity |
||
81 | * @param bool $relative Is the entity relative to the calling entity or class |
||
82 | * @param bool $recursive If entity a dir, do you want to recursively check directories |
||
83 | * |
||
84 | * @throws \InvalidArgumentException If the entity passed is not a string or array |
||
85 | */ |
||
86 | 73 | public function __construct(Vars $vars, $entity, $relative = true, $recursive = true) |
|
104 | |||
105 | /** |
||
106 | * Creates the FileResource|ResourceProvider from the resource |
||
107 | * |
||
108 | * @param array $resources The array of resources |
||
109 | * @param string $type The type of the resource |
||
110 | */ |
||
111 | 67 | private function createResources(array $resources, $type) |
|
135 | |||
136 | /** |
||
137 | * Creates the content from the entity |
||
138 | * |
||
139 | * @param string|array $entity The configuration entity |
||
140 | * @param string $type The type of entity |
||
141 | * |
||
142 | * @throws \InvalidArgumentException If the entity is not array|file, is readable or exists |
||
143 | * |
||
144 | * @returns array The array of resources |
||
145 | */ |
||
146 | 72 | private function processEntity($entity, $type) |
|
166 | |||
167 | /** |
||
168 | * Creates the content from the entity |
||
169 | * |
||
170 | * @param string $entity The configuration entity |
||
171 | * |
||
172 | * @returns string The parsed entity |
||
173 | */ |
||
174 | 72 | private function parseEntity($entity) |
|
193 | |||
194 | /** |
||
195 | * Adds content to the parent contents |
||
196 | * |
||
197 | * @param array $content The content from the resource |
||
198 | */ |
||
199 | 57 | private function addContent($content) |
|
207 | |||
208 | /** |
||
209 | * Returns the supported files using the extensions from the loaders in the entity which is a directory |
||
210 | * |
||
211 | * @see \M1\Vars\Loader\LoaderProvider::getExtensions() \M1\Vars\Loader\LoaderProvider::getExtensions() |
||
212 | * @see \M1\Vars\Loader\LoaderProvider::makeLoaders() \M1\Vars\Loader\LoaderProvider::makeLoaders() |
||
213 | * |
||
214 | * @return array|bool Returns the supported files or false if no files were found |
||
215 | */ |
||
216 | 5 | private function getSupportedFilesInDir() |
|
224 | |||
225 | /** |
||
226 | * Merges various configuration contents into one array |
||
227 | * |
||
228 | * @param mixed $contents,... Optional number of arrays to merge |
||
229 | * |
||
230 | * @return array The merged contents |
||
231 | */ |
||
232 | 59 | private function mergeContents() |
|
237 | |||
238 | /** |
||
239 | * Adds content to the parent content array |
||
240 | * |
||
241 | * @param array $content The content to add |
||
242 | */ |
||
243 | 7 | public function addParentContent(array $content) |
|
247 | |||
248 | /** |
||
249 | * Merges the content and the parent content together |
||
250 | * |
||
251 | * @return \M1\Vars\Resource\ResourceProvider |
||
252 | */ |
||
253 | 59 | public function mergeParentContent() |
|
259 | |||
260 | /** |
||
261 | * Returns the parent content |
||
262 | * |
||
263 | * @return mixed The parent content |
||
264 | */ |
||
265 | 44 | public function getParentContent() |
|
269 | } |
||
270 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.