1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework; |
4
|
|
|
|
5
|
|
|
use Composer\InstalledVersions; |
6
|
|
|
use Hyde\Framework\Contracts\HydeKernelContract; |
7
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
8
|
|
|
use Hyde\Framework\Foundation\Filesystem; |
9
|
|
|
use Hyde\Framework\Foundation\Hyperlinks; |
10
|
|
|
use Hyde\Framework\Helpers\Features; |
11
|
|
|
use Illuminate\Support\Facades\View; |
12
|
|
|
use Illuminate\Support\Str; |
13
|
|
|
use Illuminate\Support\Traits\Macroable; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Encapsulates a HydePHP project, providing helpful methods for interacting with it. |
17
|
|
|
* |
18
|
|
|
* @see \Hyde\Framework\Hyde for the facade commonly used to access this class. |
19
|
|
|
* |
20
|
|
|
* @author Caen De Silva <[email protected]> |
21
|
|
|
* @copyright 2022 Caen De Silva |
22
|
|
|
* @license MIT License |
23
|
|
|
* |
24
|
|
|
* @link https://hydephp.com/ |
25
|
|
|
*/ |
26
|
|
|
class HydeKernel implements HydeKernelContract |
27
|
|
|
{ |
28
|
|
|
use Macroable; |
29
|
|
|
|
30
|
|
|
protected string $basePath; |
31
|
|
|
protected Filesystem $filesystem; |
32
|
|
|
protected Hyperlinks $hyperlinks; |
33
|
|
|
|
34
|
|
|
public function __construct(?string $basePath = null) |
35
|
|
|
{ |
36
|
|
|
$this->setBasePath($basePath ?? getcwd()); |
37
|
|
|
$this->filesystem = new Filesystem($this); |
38
|
|
|
$this->hyperlinks = new Hyperlinks($this); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function getInstance(): HydeKernelContract |
42
|
|
|
{ |
43
|
|
|
return app(HydeKernelContract::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function version(): string |
47
|
|
|
{ |
48
|
|
|
return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getBasePath(): string |
52
|
|
|
{ |
53
|
|
|
return $this->basePath; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setBasePath(string $basePath) |
57
|
|
|
{ |
58
|
|
|
$this->basePath = rtrim($basePath, '/\\'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function features(): Features |
62
|
|
|
{ |
63
|
|
|
return new Features; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function hasFeature(string $feature): bool |
67
|
|
|
{ |
68
|
|
|
return Features::enabled($feature); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function currentPage(): string |
72
|
|
|
{ |
73
|
|
|
return View::shared('currentPage', ''); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function currentRoute(): ?RouteContract |
77
|
|
|
{ |
78
|
|
|
return View::shared('currentRoute'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function makeTitle(string $slug): string |
82
|
|
|
{ |
83
|
|
|
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but']; |
84
|
|
|
|
85
|
|
|
return ucfirst(str_ireplace( |
|
|
|
|
86
|
|
|
$alwaysLowercase, |
87
|
|
|
$alwaysLowercase, |
88
|
|
|
Str::headline($slug) |
89
|
|
|
)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function formatHtmlPath(string $destination): string |
93
|
|
|
{ |
94
|
|
|
return $this->hyperlinks->formatHtmlPath($destination); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function relativeLink(string $destination): string |
98
|
|
|
{ |
99
|
|
|
return $this->hyperlinks->relativeLink($destination); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function image(string $name): string |
103
|
|
|
{ |
104
|
|
|
return $this->hyperlinks->image($name); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function hasSiteUrl(): bool |
108
|
|
|
{ |
109
|
|
|
return $this->hyperlinks->hasSiteUrl(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function url(string $path = '', ?string $default = null): string |
113
|
|
|
{ |
114
|
|
|
return $this->hyperlinks->url($path, $default); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function path(string $path = ''): string |
118
|
|
|
{ |
119
|
|
|
return $this->filesystem->path($path); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function vendorPath(string $path = ''): string |
123
|
|
|
{ |
124
|
|
|
return $this->filesystem->vendorPath($path); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function copy(string $from, string $to): bool |
128
|
|
|
{ |
129
|
|
|
return $this->filesystem->copy($from, $to); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function touch(string|array $path): bool |
133
|
|
|
{ |
134
|
|
|
return $this->filesystem->touch($path); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function unlink(string|array $path): bool |
138
|
|
|
{ |
139
|
|
|
return $this->filesystem->unlink($path); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getModelSourcePath(string $model, string $path = ''): string |
143
|
|
|
{ |
144
|
|
|
return $this->filesystem->getModelSourcePath($model, $path); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getBladePagePath(string $path = ''): string |
148
|
|
|
{ |
149
|
|
|
return $this->filesystem->getBladePagePath($path); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function getMarkdownPagePath(string $path = ''): string |
153
|
|
|
{ |
154
|
|
|
return $this->filesystem->getMarkdownPagePath($path); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function getMarkdownPostPath(string $path = ''): string |
158
|
|
|
{ |
159
|
|
|
return $this->filesystem->getMarkdownPostPath($path); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function getDocumentationPagePath(string $path = ''): string |
163
|
|
|
{ |
164
|
|
|
return $this->filesystem->getDocumentationPagePath($path); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function getSiteOutputPath(string $path = ''): string |
168
|
|
|
{ |
169
|
|
|
return $this->filesystem->getSiteOutputPath($path); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function pathToRelative(string $path): string |
173
|
|
|
{ |
174
|
|
|
return $this->filesystem->pathToRelative($path); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|