1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hyde\Foundation\Concerns; |
6
|
|
|
|
7
|
|
|
use Hyde\Foundation\FileCollection; |
8
|
|
|
use Hyde\Foundation\HydeKernel; |
9
|
|
|
use Hyde\Foundation\PageCollection; |
10
|
|
|
use Hyde\Foundation\RouteCollection; |
11
|
|
|
use Hyde\Pages\Concerns\HydePage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @internal Single-use trait for the HydeKernel class. |
15
|
|
|
* |
16
|
|
|
* @see \Hyde\Foundation\HydeKernel |
17
|
|
|
*/ |
18
|
|
|
trait ManagesHydeKernel |
19
|
|
|
{ |
20
|
|
|
public function boot(): void |
21
|
|
|
{ |
22
|
|
|
$this->booted = true; |
|
|
|
|
23
|
|
|
|
24
|
|
|
$this->files = FileCollection::boot($this); |
|
|
|
|
25
|
|
|
$this->pages = PageCollection::boot($this); |
|
|
|
|
26
|
|
|
$this->routes = RouteCollection::boot($this); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public static function getInstance(): HydeKernel |
30
|
|
|
{ |
31
|
|
|
return static::$instance; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function setInstance(HydeKernel $instance): void |
35
|
|
|
{ |
36
|
|
|
static::$instance = $instance; |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function setBasePath(string $basePath): void |
40
|
|
|
{ |
41
|
|
|
$this->basePath = rtrim($basePath, '/\\'); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getBasePath(): string |
45
|
|
|
{ |
46
|
|
|
return $this->basePath; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setSourceRoot(string $sourceRoot): void |
50
|
|
|
{ |
51
|
|
|
$this->sourceRoot = rtrim($sourceRoot, '/\\'); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getSourceRoot(): string |
55
|
|
|
{ |
56
|
|
|
return $this->sourceRoot; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @return array<class-string<\Hyde\Pages\Concerns\HydePage>> */ |
|
|
|
|
60
|
|
|
public function getDiscoveredPageTypes(): array |
61
|
|
|
{ |
62
|
|
|
return $this->pages()->map(function (HydePage $page): string { |
|
|
|
|
63
|
|
|
return $page::class; |
64
|
|
|
})->unique()->values()->toArray(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|