| 1 | <?php |
||
| 10 | class ModelMapper extends ClassReader |
||
| 11 | { |
||
| 12 | public static $models = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Maps subclasses of Illuminate\Database\Eloquent\Model |
||
| 16 | * found in app_path() |
||
| 17 | * |
||
| 18 | * @return array |
||
| 19 | */ |
||
| 20 | public static function map(): array |
||
| 21 | { |
||
| 22 | $paths = config('schematics.model.paths', [app_path()]); |
||
| 23 | |||
| 24 | foreach ($paths as $path) { |
||
| 25 | $files = new RecursiveIteratorIterator( |
||
| 26 | new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST |
||
| 27 | ); |
||
| 28 | |||
| 29 | foreach ($files as $file) { |
||
| 30 | if (self::readablePhp($file)) { |
||
| 31 | $class = self::getClassName($file); |
||
| 32 | |||
| 33 | if (is_subclass_of($class, Model::class)) { |
||
| 34 | self::$models[] = $class; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | return self::$models; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param SplFileInfo $file |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | private static function readablePhp(SplFileInfo $file): bool |
||
| 54 | } |
||
| 55 |