1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework; |
4
|
|
|
|
5
|
|
|
use Composer\InstalledVersions; |
6
|
|
|
use Hyde\Framework\Concerns\JsonSerializesArrayable; |
7
|
|
|
use Hyde\Framework\Contracts\HydeKernelContract; |
8
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
9
|
|
|
use Hyde\Framework\Foundation\FileCollection; |
10
|
|
|
use Hyde\Framework\Foundation\Filesystem; |
11
|
|
|
use Hyde\Framework\Foundation\Hyperlinks; |
12
|
|
|
use Hyde\Framework\Foundation\PageCollection; |
13
|
|
|
use Hyde\Framework\Foundation\RouteCollection; |
14
|
|
|
use Hyde\Framework\Helpers\Features; |
15
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
16
|
|
|
use Illuminate\Support\Facades\View; |
17
|
|
|
use Illuminate\Support\Traits\Macroable; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Encapsulates a HydePHP project, providing helpful methods for interacting with it. |
21
|
|
|
* |
22
|
|
|
* @see \Hyde\Framework\Hyde for the facade commonly used to access this class. |
23
|
|
|
* |
24
|
|
|
* @author Caen De Silva <[email protected]> |
25
|
|
|
* @copyright 2022 Caen De Silva |
26
|
|
|
* @license MIT License |
27
|
|
|
* |
28
|
|
|
* @link https://hydephp.com/ |
29
|
|
|
*/ |
30
|
|
|
class HydeKernel implements HydeKernelContract, Arrayable, \JsonSerializable |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
use Foundation\Concerns\HandlesFoundationCollections; |
33
|
|
|
use Foundation\Concerns\ImplementsStringHelpers; |
34
|
|
|
use Foundation\Concerns\ForwardsHyperlinks; |
35
|
|
|
use Foundation\Concerns\ForwardsFilesystem; |
36
|
|
|
use Foundation\Concerns\ManagesHydeKernel; |
37
|
|
|
|
38
|
|
|
use JsonSerializesArrayable; |
39
|
|
|
use Macroable; |
|
|
|
|
40
|
|
|
|
41
|
|
|
protected static HydeKernel $instance; |
42
|
|
|
|
43
|
|
|
protected string $basePath; |
44
|
|
|
|
45
|
|
|
protected Filesystem $filesystem; |
46
|
|
|
protected Hyperlinks $hyperlinks; |
47
|
|
|
|
48
|
|
|
protected FileCollection $files; |
49
|
|
|
protected PageCollection $pages; |
50
|
|
|
protected RouteCollection $routes; |
51
|
|
|
|
52
|
|
|
protected bool $booted = false; |
53
|
|
|
|
54
|
|
|
public function __construct(?string $basePath = null) |
55
|
|
|
{ |
56
|
|
|
$this->setBasePath($basePath ?? getcwd()); |
57
|
|
|
$this->filesystem = new Filesystem($this); |
58
|
|
|
$this->hyperlinks = new Hyperlinks($this); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public static function version(): string |
62
|
|
|
{ |
63
|
|
|
return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function features(): Features |
67
|
|
|
{ |
68
|
|
|
return new Features; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function hasFeature(string $feature): bool |
72
|
|
|
{ |
73
|
|
|
return Features::enabled($feature); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function currentPage(): string |
77
|
|
|
{ |
78
|
|
|
return View::shared('currentPage', ''); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function currentRoute(): ?RouteContract |
82
|
|
|
{ |
83
|
|
|
return View::shared('currentRoute'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritDoc |
88
|
|
|
* |
89
|
|
|
* @return array{basePath: string, features: \Hyde\Framework\Helpers\Features, pages: \Hyde\Framework\Foundation\PageCollection, routes: \Hyde\Framework\Foundation\RouteCollection} |
90
|
|
|
*/ |
91
|
|
|
public function toArray(): array |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
|
|
'basePath' => $this->basePath, |
95
|
|
|
'features' => $this->features(), |
96
|
|
|
'files' => $this->files(), |
97
|
|
|
'pages' => $this->pages(), |
98
|
|
|
'routes' => $this->routes(), |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.