|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Foundation; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Contracts\AbstractPage; |
|
6
|
|
|
use Hyde\Framework\Helpers\Features; |
|
7
|
|
|
use Hyde\Framework\Models\File; |
|
|
|
|
|
|
8
|
|
|
use Hyde\Framework\Models\Pages\BladePage; |
|
9
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
|
10
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPage; |
|
11
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPost; |
|
12
|
|
|
use Hyde\Framework\Services\DiscoveryService; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @see \Hyde\Framework\Foundation\FileCollection |
|
16
|
|
|
*/ |
|
17
|
|
|
final class FileCollection extends BaseSystemCollection |
|
18
|
|
|
{ |
|
19
|
|
|
public function getSourceFiles(?string $pageClass = null): self |
|
20
|
|
|
{ |
|
21
|
|
|
return ! $pageClass ? $this->getAllSourceFiles() : $this->getSourceFilesFor($pageClass); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getAllSourceFiles(): self |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->filter(function (File $file) { |
|
27
|
|
|
return $file->belongsTo !== null; |
|
28
|
|
|
}); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getSourceFilesFor(string $pageClass): self |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->filter(function (File $file) use ($pageClass): bool { |
|
34
|
|
|
return $file->belongsTo() === $pageClass; |
|
35
|
|
|
}); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getMediaFiles(): self |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->filter(function (File $file): bool { |
|
41
|
|
|
return str_starts_with($file, '_media'); |
|
42
|
|
|
}); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function runDiscovery(): self |
|
46
|
|
|
{ |
|
47
|
|
|
if (Features::hasBladePages()) { |
|
48
|
|
|
$this->discoverFilesFor(BladePage::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (Features::hasMarkdownPages()) { |
|
52
|
|
|
$this->discoverFilesFor(MarkdownPage::class); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if (Features::hasBlogPosts()) { |
|
56
|
|
|
$this->discoverFilesFor(MarkdownPost::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (Features::hasDocumentationPages()) { |
|
60
|
|
|
$this->discoverFilesFor(DocumentationPage::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->discoverMediaAssetFiles(); |
|
64
|
|
|
|
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** @param string<AbstractPage> $pageClass */ |
|
69
|
|
|
protected function discoverFilesFor(string $pageClass): void |
|
70
|
|
|
{ |
|
71
|
|
|
// Scan the source directory, and directories therein, for files that match the model's file extension. |
|
72
|
|
|
foreach (glob($this->kernel->path($pageClass::qualifyBasename('{*,**/*}')), GLOB_BRACE) as $filepath) { |
|
|
|
|
|
|
73
|
|
|
if (! str_starts_with(basename($filepath), '_')) { |
|
74
|
|
|
$this->put($this->kernel->pathToRelative($filepath), File::make($filepath)->belongsTo($pageClass)); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function discoverMediaAssetFiles(): void |
|
80
|
|
|
{ |
|
81
|
|
|
foreach (DiscoveryService::getMediaAssetFiles() as $filepath) { |
|
82
|
|
|
$this->put($this->kernel->pathToRelative($filepath), File::make($filepath)); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths