dimaslanjaka /
universal-framework
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Filemanager; |
||||
| 4 | |||||
| 5 | use RecursiveDirectoryIterator; |
||||
| 6 | use RecursiveIteratorIterator; |
||||
| 7 | |||||
| 8 | class scan |
||||
| 9 | { |
||||
| 10 | public static $static = null; |
||||
| 11 | public static $opt; |
||||
| 12 | |||||
| 13 | public function __construct($opt = []) |
||||
| 14 | { |
||||
| 15 | self::$opt = $opt; |
||||
| 16 | } |
||||
| 17 | |||||
| 18 | public static function getStatic() |
||||
| 19 | { |
||||
| 20 | if (null === self::$static) { |
||||
| 21 | self::$static = new self(self::$opt); |
||||
| 22 | } |
||||
| 23 | |||||
| 24 | return self::$static; |
||||
| 25 | } |
||||
| 26 | |||||
| 27 | public static function scanAllFiles($dir, $exclude = '/^(.{1,2}|\.htaccess)$/s') |
||||
| 28 | { |
||||
| 29 | $di = new RecursiveDirectoryIterator($dir); |
||||
| 30 | $result = []; |
||||
| 31 | foreach (new RecursiveIteratorIterator($di) as $filename => $file) { |
||||
| 32 | $basename = basename($filename); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 33 | if (preg_match($exclude, $basename)) { |
||||
| 34 | continue; |
||||
| 35 | } |
||||
| 36 | $b['path'] = realpath($filename); |
||||
|
0 ignored issues
–
show
It seems like
$filename can also be of type null and true; however, parameter $path of realpath() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 37 | $b['data'] = \Filemanager\file::get(realpath($filename), true); |
||||
| 38 | $b['folder'] = dirname(realpath($filename)); |
||||
| 39 | $b['filename'] = $basename; |
||||
| 40 | $b['size'] = $file->getSize(); |
||||
| 41 | $result[] = $b; |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | return (array) $result; |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | public static function scandir($dir) |
||||
| 48 | { |
||||
| 49 | return self::scanAllFiles($dir); |
||||
| 50 | } |
||||
| 51 | } |
||||
| 52 |