8
8
use FQ \Dirs \RootDir ;
9
9
use FQ \Exceptions \FilesException ;
10
10
use FQ \Query \FilesQuery ;
11
+ use FQ \Query \FilesQueryRequirements ;
11
12
use FQ \Query \Selection \ChildSelection ;
12
13
use FQ \Query \Selection \RootSelection ;
13
14
@@ -31,7 +32,6 @@ class Files {
31
32
*/
32
33
private $ _query ;
33
34
34
-
35
35
const DEFAULT_EXTENSION = 'php ' ;
36
36
37
37
function __construct () {
@@ -68,7 +68,7 @@ public function rootDirs() {
68
68
* @param RootDir $rootDir RootDir that will be checked
69
69
* @return bool Returns true if RootDir is part of this files instance
70
70
*/
71
- public function isRootDirOf (RootDir $ rootDir ) {
71
+ public function containsRootDir (RootDir $ rootDir ) {
72
72
return $ this ->_rootDirs ()->isInCollection ($ rootDir );
73
73
}
74
74
@@ -140,7 +140,7 @@ public function childDirs() {
140
140
* @param ChildDir $childDir Dir that will be checked
141
141
* @return bool Returns true if dir is part of this files instance
142
142
*/
143
- public function isChildDirOf (ChildDir $ childDir ) {
143
+ public function containsChildDir (ChildDir $ childDir ) {
144
144
return $ this ->_childDirs ()->isInCollection ($ childDir );
145
145
}
146
146
@@ -207,9 +207,6 @@ protected function isValid() {
207
207
return true ;
208
208
}
209
209
210
-
211
-
212
-
213
210
/**
214
211
* @param string|RootDir $rootDir
215
212
* @param string|ChildDir $childDir
@@ -229,31 +226,31 @@ public function getFullPath($rootDir, $childDir) {
229
226
230
227
/**
231
228
* @param string $fileName
232
- * @param null|string|ChildDir[] $children
229
+ * @param ChildSelection $childSelection
230
+ * @param RootSelection $rootSelection
233
231
* @param bool $reverseLoad
234
- * @return null |string
232
+ * @return false |string
235
233
*/
236
- public function filePath ($ fileName , $ children = null , $ reverseLoad = true ) {
237
- $ query = $ this ->query ($ children );
234
+ public function queryPath ($ fileName , ChildSelection $ childSelection = null , RootSelection $ rootSelection = null , $ reverseLoad = true ) {
235
+ $ query = $ this ->query ($ rootSelection , $ childSelection , true , true );
238
236
$ query ->reverse ($ reverseLoad );
239
- $ query ->requirements (FilesQuery::LEVELS_ONE );
240
- $ query ->run ($ fileName );
241
-
242
- $ paths = $ query ->listPaths ();
243
- if (count ($ paths )) {
244
- foreach ($ paths as $ path ) return $ path ;
237
+ $ query ->requirements (FilesQueryRequirements::LEVELS_ONE );
238
+ if ($ query ->run ($ fileName )) {
239
+ $ paths = $ query ->listPaths ();
240
+ if (count ($ paths )) foreach ($ paths as $ path ) return $ path ;
245
241
}
246
242
return false ;
247
243
}
248
244
249
245
/**
250
246
* @param string $fileName
251
- * @param null|string|ChildDir[] $children
247
+ * @param ChildSelection $childSelection
248
+ * @param RootSelection $rootSelection
252
249
* @param bool $reverseLoad
253
250
* @return bool
254
251
*/
255
- public function loadFile ($ fileName , $ children = null , $ reverseLoad = true ) {
256
- $ path = $ this ->filePath ($ fileName , $ children , $ reverseLoad );
252
+ public function loadFile ($ fileName , ChildSelection $ childSelection = null , RootSelection $ rootSelection = null , $ reverseLoad = true ) {
253
+ $ path = $ this ->queryPath ($ fileName , $ childSelection , $ rootSelection , $ reverseLoad );
257
254
if ($ path ) {
258
255
return $ this ->requireOnce ($ path );
259
256
}
@@ -268,26 +265,32 @@ public function loadFile($fileName, $children = null, $reverseLoad = true) {
268
265
* @param bool $reverseLoad
269
266
* @return bool
270
267
*/
271
- public function loadFiles ($ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null , $ requiredLevels = FilesQuery::LEVELS_ONE , $ reverseLoad = true ) {
272
- $ query = $ this ->query ($ rootDirs , $ children , true , true );
273
- $ query ->reverse ($ reverseLoad );
274
- $ query ->requirements ($ requiredLevels );
275
- $ query ->run ($ fileName );
276
-
277
- foreach ($ query ->listPaths () as $ file ) {
278
- $ this ->requireOnce ($ file );
268
+ public function loadFiles ($ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null , $ requiredLevels = FilesQueryRequirements::LEVELS_ONE , $ reverseLoad = true )
269
+ {
270
+ $ query = $ this ->query ($ rootDirs , $ children , true , true );
271
+ $ query ->reverse ($ reverseLoad );
272
+ $ query ->requirements ($ requiredLevels );
273
+ if ($ query ->run ($ fileName )) {
274
+ $ paths = $ query ->listPaths ();
275
+ if (count ($ paths )) {
276
+ foreach ($ query ->listPaths () as $ file ) {
277
+ $ this ->includeOnce ($ file );
278
+ }
279
+ return true ;
280
+ }
279
281
}
280
- return true ;
282
+ return false ;
281
283
}
282
284
283
285
/**
284
286
* @param string $fileName
285
287
* @param RootSelection $rootDirs
286
288
* @param ChildSelection $children
287
- * @return FilesQuery
289
+ * @return array
288
290
*/
289
- public function getFilePaths ($ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null ) {
290
- $ query = $ this ->queryRun ($ fileName , $ rootDirs , $ children , true , true );
291
+ public function queryPaths ($ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null ) {
292
+ $ query = $ this ->query ($ rootDirs , $ children , true , true );
293
+ $ query ->run ($ fileName );
291
294
return $ query ->listPaths ();
292
295
}
293
296
@@ -298,7 +301,8 @@ public function getFilePaths($fileName, RootSelection $rootDirs = null, ChildSel
298
301
* @return bool
299
302
*/
300
303
public function fileExists ($ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null ) {
301
- $ query = $ this ->queryRun ($ fileName , $ rootDirs , $ children , true , true );
304
+ $ query = $ this ->query ($ rootDirs , $ children , true , true );
305
+ $ query ->run ($ fileName );
302
306
return $ query ->hasPaths ();
303
307
}
304
308
@@ -323,19 +327,15 @@ public function query(RootSelection $rootDirs = null, ChildSelection $children =
323
327
}
324
328
325
329
/**
326
- * A basic query wrapper
330
+ * Very simple include function wrapper. Ready to be extended when necessary.
327
331
*
328
- * @param string $fileName
329
- * @param RootSelection $rootDirs
330
- * @param ChildSelection $children
331
- * @param bool $resetQuery
332
- * @param bool $resetSelection
333
- * @return FilesQuery
332
+ * @param string $file
333
+ * @return bool
334
334
*/
335
- public function queryRun ( $ fileName , RootSelection $ rootDirs = null , ChildSelection $ children = null , $ resetQuery = true , $ resetSelection = false ) {
336
- $ query = $ this -> query ( $ rootDirs , $ children , $ resetQuery , $ resetSelection );
337
- $ query -> run ( $ fileName ) ;
338
- return $ query ;
335
+ protected function includeOnce ( $ file ) {
336
+ /** @noinspection PhpIncludeInspection */
337
+ include_once $ file ;
338
+ return true ;
339
339
}
340
340
341
341
/**
0 commit comments