@@ -105,6 +105,23 @@ final protected static function _getRealPath($path) {
105
105
return str_replace (array_keys ($ replacements ), array_values ($ replacements ), $ path );
106
106
}
107
107
108
+ final protected static function _scanShortcuts ($ scandir , $ opt ) {
109
+ $ filename = is_string ($ opt ) ? str_replace ('/ ' , '' , $ opt ) : '.shortcuts.json ' ;
110
+ $ path = preg_replace ('/\/?$/ ' , '/ ' . $ filename , $ scandir );
111
+ $ result = [];
112
+
113
+ if ( file_exists ($ path ) ) {
114
+ try {
115
+ $ json = json_decode (file_get_contents ($ path ), true );
116
+ if ( is_array ($ json ) ) {
117
+ $ result = $ json ;
118
+ }
119
+ } catch ( Exception $ e ) {}
120
+ }
121
+
122
+ return $ result ;
123
+ }
124
+
108
125
final public static function exists (Request $ request , Array $ arguments = []) {
109
126
return file_exists (self ::_getRealPath ($ arguments ['path ' ]));
110
127
}
@@ -276,16 +293,25 @@ final public static function fileinfo(Request $request, Array $arguments = []) {
276
293
}
277
294
278
295
final public static function scandir (Request $ request , Array $ arguments = []) {
296
+ $ opts = isset ($ arguments ['options ' ]) ? $ arguments ['options ' ] : [];
279
297
$ path = self ::_getRealPath ($ arguments ['path ' ]);
298
+
280
299
if ( !file_exists ($ path ) || !is_dir ($ path ) ) {
281
300
throw new Exception ("Directory does not exist " );
282
301
}
283
302
284
- return array_values (array_map (function ($ iter ) use ($ arguments , $ path ) {
303
+ $ result = array_values (array_map (function ($ iter ) use ($ arguments , $ path ) {
285
304
return self ::_getFileMetadata ($ iter , $ arguments ['path ' ], $ path . '/ ' . $ iter );
286
305
}, array_filter (scandir ($ path ), function ($ iter ) {
287
306
return !in_array ($ iter , ['. ' , '.. ' ]);
288
307
})));
308
+
309
+ $ shortcuts = isset ($ opts ['shortcuts ' ]) ? (is_string ($ opts ['shortcuts ' ]) || $ opts ['shortcuts ' ] === true ) : true ;
310
+ if ( $ shortcuts ) {
311
+ $ result = array_merge ($ result , self ::_scanShortcuts ($ path , $ shortcuts ));
312
+ }
313
+
314
+ return $ result ;
289
315
}
290
316
291
317
final public static function freeSpace (Request $ request , Array $ arguments = []) {
0 commit comments