1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework; |
4
|
|
|
|
5
|
|
|
use Composer\InstalledVersions; |
6
|
|
|
use Hyde\Framework\Concerns\JsonSerializesArrayable; |
7
|
|
|
use Hyde\Framework\Foundation\FileCollection; |
8
|
|
|
use Hyde\Framework\Foundation\Filesystem; |
9
|
|
|
use Hyde\Framework\Foundation\Hyperlinks; |
10
|
|
|
use Hyde\Framework\Foundation\PageCollection; |
11
|
|
|
use Hyde\Framework\Foundation\RouteCollection; |
12
|
|
|
use Hyde\Framework\Helpers\Features; |
13
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
14
|
|
|
use Illuminate\Support\Traits\Macroable; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Encapsulates a HydePHP project, providing helpful methods for interacting with it. |
18
|
|
|
* |
19
|
|
|
* @see \Hyde\Framework\Hyde for the facade commonly used to access this class. |
20
|
|
|
* |
21
|
|
|
* @author Caen De Silva <[email protected]> |
22
|
|
|
* @copyright 2022 Caen De Silva |
23
|
|
|
* @license MIT License |
24
|
|
|
* |
25
|
|
|
* @link https://hydephp.com/ |
26
|
|
|
* |
27
|
|
|
* @extra Usage information: |
28
|
|
|
* |
29
|
|
|
* The HydeKernel It is stored as a singleton in this class, and is bound into the |
30
|
|
|
* Laravel Application Service Container, and can be accessed in a few ways. |
31
|
|
|
* |
32
|
|
|
* Commonly, you'll use the Hyde facade, but you can also use Dependency Injection |
33
|
|
|
* by type-hinting the HydeKernel::class, or use the hyde() function to get the Kernel. |
34
|
|
|
* |
35
|
|
|
* The Kernel instance is constructed in bootstrap.php, and is available globally as $hyde. |
36
|
|
|
*/ |
37
|
|
|
class HydeKernel implements Arrayable, \JsonSerializable |
38
|
|
|
{ |
39
|
|
|
use Foundation\Concerns\HandlesFoundationCollections; |
40
|
|
|
use Foundation\Concerns\ImplementsStringHelpers; |
41
|
|
|
use Foundation\Concerns\ForwardsHyperlinks; |
42
|
|
|
use Foundation\Concerns\ForwardsFilesystem; |
43
|
|
|
use Foundation\Concerns\ManagesHydeKernel; |
44
|
|
|
use Foundation\Concerns\ManagesViewData; |
45
|
|
|
|
46
|
|
|
use JsonSerializesArrayable; |
47
|
|
|
use Macroable; |
|
|
|
|
48
|
|
|
|
49
|
|
|
protected static HydeKernel $instance; |
50
|
|
|
|
51
|
|
|
protected string $basePath; |
52
|
|
|
|
53
|
|
|
protected Filesystem $filesystem; |
54
|
|
|
protected Hyperlinks $hyperlinks; |
55
|
|
|
|
56
|
|
|
protected FileCollection $files; |
57
|
|
|
protected PageCollection $pages; |
58
|
|
|
protected RouteCollection $routes; |
59
|
|
|
|
60
|
|
|
protected bool $booted = false; |
61
|
|
|
|
62
|
|
|
public function __construct(?string $basePath = null) |
63
|
|
|
{ |
64
|
|
|
$this->setBasePath($basePath ?? getcwd()); |
65
|
|
|
$this->filesystem = new Filesystem($this); |
66
|
|
|
$this->hyperlinks = new Hyperlinks($this); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function version(): string |
70
|
|
|
{ |
71
|
|
|
return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function features(): Features |
75
|
|
|
{ |
76
|
|
|
return new Features; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function hasFeature(string $feature): bool |
80
|
|
|
{ |
81
|
|
|
return Features::enabled($feature); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritDoc |
86
|
|
|
* |
87
|
|
|
* @return array{basePath: string, features: \Hyde\Framework\Helpers\Features, pages: \Hyde\Framework\Foundation\PageCollection, routes: \Hyde\Framework\Foundation\RouteCollection} |
88
|
|
|
*/ |
89
|
|
|
public function toArray(): array |
90
|
|
|
{ |
91
|
|
|
return [ |
92
|
|
|
'basePath' => $this->basePath, |
93
|
|
|
'features' => $this->features(), |
94
|
|
|
'files' => $this->files(), |
95
|
|
|
'pages' => $this->pages(), |
96
|
|
|
'routes' => $this->routes(), |
97
|
|
|
]; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|