|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Foundation\Facades; |
|
6
|
|
|
|
|
7
|
|
|
use Hyde\Foundation\HydeKernel; |
|
8
|
|
|
use Hyde\Foundation\Kernel\FileCollection; |
|
9
|
|
|
use Hyde\Framework\Exceptions\FileNotFoundException; |
|
10
|
|
|
use Hyde\Support\Filesystem\ProjectFile; |
|
11
|
|
|
use Hyde\Support\Filesystem\SourceFile; |
|
12
|
|
|
use Illuminate\Support\Facades\Facade; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @mixin \Hyde\Foundation\Kernel\FileCollection |
|
16
|
|
|
*/ |
|
17
|
|
|
class Files extends Facade |
|
18
|
|
|
{ |
|
19
|
|
|
public static function getFile(string $filePath): ProjectFile |
|
20
|
|
|
{ |
|
21
|
|
|
return static::getFacadeRoot()->get($filePath) ?? throw new FileNotFoundException(message: "File [$filePath] not found in file collection"); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param class-string<\Hyde\Pages\Concerns\HydePage>|null $pageClass |
|
|
|
|
|
|
26
|
|
|
* @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile> |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function getSourceFiles(?string $pageClass = null): FileCollection |
|
29
|
|
|
{ |
|
30
|
|
|
return $pageClass ? static::getSourceFilesFor($pageClass) : static::getAllSourceFiles(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param class-string<\Hyde\Pages\Concerns\HydePage> $pageClass |
|
|
|
|
|
|
35
|
|
|
* @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile> |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function getSourceFilesFor(string $pageClass): FileCollection |
|
38
|
|
|
{ |
|
39
|
|
|
return static::getAllSourceFiles()->where(fn (SourceFile $file): bool => $file->model === $pageClass); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile> */ |
|
43
|
|
|
public static function getAllSourceFiles(): FileCollection |
|
44
|
|
|
{ |
|
45
|
|
|
return static::getFacadeRoot()->where(fn (ProjectFile $file): bool => $file instanceof SourceFile); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\ProjectFile> */ |
|
49
|
|
|
public static function getFacadeRoot(): FileCollection |
|
50
|
|
|
{ |
|
51
|
|
|
return HydeKernel::getInstance()->files(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|