-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilesystem.php
52 lines (35 loc) · 1.29 KB
/
Filesystem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace BlueRaster\PowerBIAuthProxy;
use BlueRaster\PowerBIAuthProxy\Exceptions\IllegalClassDirectoryListException;
use Illuminate\Filesystem\Filesystem as IlluminateFilesystem;
use Illuminate\Support\Str;
class Filesystem{
protected static $allowed_class_directories = ['Frameworks', 'UserProviders', 'Exceptions'];
public static function files($dir){
return collect((new IlluminateFilesystem)->files($dir));
}
public static function allFiles($dir){
return collect((new IlluminateFilesystem)->allFiles($dir));
}
public static function list_classes($dir){
$sanitized_dir = basename($dir);
if(!in_array($sanitized_dir, self::$allowed_class_directories)){
throw new IllegalClassDirectoryListException;
}
return Filesystem::files(__DIR__."/$sanitized_dir")->map(function($splFile) use($sanitized_dir){
$name = $splFile->getFilenameWithoutExtension();
return $name !== Str::singular($sanitized_dir) ? new ClassIterable("$sanitized_dir\\$name") : null;
})->filter();
}
}
class ClassIterable{
public $classname;
// public $classname;
public function __construct($classname){
$namespace = (new \ReflectionClass($this))->getNamespaceName();
$this->classname = "$namespace\\$classname";
}
public function __toString(){
return $this->classname;
}
}