Skip to content

Commit 4f4e75e

Browse files
author
github-actions
committed
Merge pull request #429 from hydephp/organize-and-restructure-code
Refactor HydeKernel code to organized single-used traits hydephp/develop@9f91a20
1 parent ae75248 commit 4f4e75e

File tree

4 files changed

+146
-107
lines changed

4 files changed

+146
-107
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Hyde\Framework\Foundation\Concerns;
4+
5+
/**
6+
* @internal Single-use trait for the HydeKernel class.
7+
*
8+
* @see \Hyde\Framework\HydeKernel
9+
*/
10+
trait ForwardsFilesystem
11+
{
12+
public function path(string $path = ''): string
13+
{
14+
return $this->filesystem->path($path);
15+
}
16+
17+
public function vendorPath(string $path = ''): string
18+
{
19+
return $this->filesystem->vendorPath($path);
20+
}
21+
22+
public function copy(string $from, string $to): bool
23+
{
24+
return $this->filesystem->copy($from, $to);
25+
}
26+
27+
public function touch(string|array $path): bool
28+
{
29+
return $this->filesystem->touch($path);
30+
}
31+
32+
public function unlink(string|array $path): bool
33+
{
34+
return $this->filesystem->unlink($path);
35+
}
36+
37+
public function getModelSourcePath(string $model, string $path = ''): string
38+
{
39+
return $this->filesystem->getModelSourcePath($model, $path);
40+
}
41+
42+
public function getBladePagePath(string $path = ''): string
43+
{
44+
return $this->filesystem->getBladePagePath($path);
45+
}
46+
47+
public function getMarkdownPagePath(string $path = ''): string
48+
{
49+
return $this->filesystem->getMarkdownPagePath($path);
50+
}
51+
52+
public function getMarkdownPostPath(string $path = ''): string
53+
{
54+
return $this->filesystem->getMarkdownPostPath($path);
55+
}
56+
57+
public function getDocumentationPagePath(string $path = ''): string
58+
{
59+
return $this->filesystem->getDocumentationPagePath($path);
60+
}
61+
62+
public function getSiteOutputPath(string $path = ''): string
63+
{
64+
return $this->filesystem->getSiteOutputPath($path);
65+
}
66+
67+
public function pathToRelative(string $path): string
68+
{
69+
return $this->filesystem->pathToRelative($path);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Hyde\Framework\Foundation\Concerns;
4+
5+
/**
6+
* @internal Single-use trait for the HydeKernel class.
7+
*
8+
* @see \Hyde\Framework\HydeKernel
9+
*/
10+
trait ForwardsHyperlinks
11+
{
12+
public function formatHtmlPath(string $destination): string
13+
{
14+
return $this->hyperlinks->formatHtmlPath($destination);
15+
}
16+
17+
public function relativeLink(string $destination): string
18+
{
19+
return $this->hyperlinks->relativeLink($destination);
20+
}
21+
22+
public function image(string $name, bool $preferQualifiedUrl = false): string
23+
{
24+
return $this->hyperlinks->image($name, $preferQualifiedUrl);
25+
}
26+
27+
public function hasSiteUrl(): bool
28+
{
29+
return $this->hyperlinks->hasSiteUrl();
30+
}
31+
32+
public function url(string $path = '', ?string $default = null): string
33+
{
34+
return $this->hyperlinks->url($path, $default);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Hyde\Framework\Foundation\Concerns;
4+
5+
use Illuminate\Support\Str;
6+
7+
/**
8+
* @internal Single-use trait for the HydeKernel class.
9+
*
10+
* @see \Hyde\Framework\HydeKernel
11+
*/
12+
trait ImplementsStringHelpers
13+
{
14+
public function makeTitle(string $slug): string
15+
{
16+
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];
17+
18+
return ucfirst(str_ireplace(
19+
$alwaysLowercase,
20+
$alwaysLowercase,
21+
Str::headline($slug)
22+
));
23+
}
24+
}

src/HydeKernel.php

+15-107
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Hyde\Framework\Helpers\Features;
1515
use Illuminate\Contracts\Support\Arrayable;
1616
use Illuminate\Support\Facades\View;
17-
use Illuminate\Support\Str;
1817
use Illuminate\Support\Traits\Macroable;
1918

2019
/**
@@ -30,8 +29,12 @@
3029
*/
3130
class HydeKernel implements HydeKernelContract, Arrayable, \JsonSerializable
3231
{
33-
use Macroable;
32+
use Foundation\Concerns\ImplementsStringHelpers;
33+
use Foundation\Concerns\ForwardsHyperlinks;
34+
use Foundation\Concerns\ForwardsFilesystem;
35+
3436
use JsonSerializesArrayable;
37+
use Macroable;
3538

3639
protected static HydeKernel $instance;
3740

@@ -109,127 +112,25 @@ public function currentRoute(): ?RouteContract
109112

110113
public function files(): FileCollection
111114
{
112-
if (! $this->booted) {
113-
$this->boot();
114-
}
115+
$this->needsToBeBooted();
115116

116117
return $this->files;
117118
}
118119

119120
public function pages(): PageCollection
120121
{
121-
if (! $this->booted) {
122-
$this->boot();
123-
}
122+
$this->needsToBeBooted();
124123

125124
return $this->pages;
126125
}
127126

128127
public function routes(): RouteCollection
129128
{
130-
if (! $this->booted) {
131-
$this->boot();
132-
}
129+
$this->needsToBeBooted();
133130

134131
return $this->routes;
135132
}
136133

137-
public function makeTitle(string $slug): string
138-
{
139-
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];
140-
141-
return ucfirst(str_ireplace(
142-
$alwaysLowercase,
143-
$alwaysLowercase,
144-
Str::headline($slug)
145-
));
146-
}
147-
148-
public function formatHtmlPath(string $destination): string
149-
{
150-
return $this->hyperlinks->formatHtmlPath($destination);
151-
}
152-
153-
public function relativeLink(string $destination): string
154-
{
155-
return $this->hyperlinks->relativeLink($destination);
156-
}
157-
158-
public function image(string $name, bool $preferQualifiedUrl = false): string
159-
{
160-
return $this->hyperlinks->image($name, $preferQualifiedUrl);
161-
}
162-
163-
public function hasSiteUrl(): bool
164-
{
165-
return $this->hyperlinks->hasSiteUrl();
166-
}
167-
168-
public function url(string $path = '', ?string $default = null): string
169-
{
170-
return $this->hyperlinks->url($path, $default);
171-
}
172-
173-
public function path(string $path = ''): string
174-
{
175-
return $this->filesystem->path($path);
176-
}
177-
178-
public function vendorPath(string $path = ''): string
179-
{
180-
return $this->filesystem->vendorPath($path);
181-
}
182-
183-
public function copy(string $from, string $to): bool
184-
{
185-
return $this->filesystem->copy($from, $to);
186-
}
187-
188-
public function touch(string|array $path): bool
189-
{
190-
return $this->filesystem->touch($path);
191-
}
192-
193-
public function unlink(string|array $path): bool
194-
{
195-
return $this->filesystem->unlink($path);
196-
}
197-
198-
public function getModelSourcePath(string $model, string $path = ''): string
199-
{
200-
return $this->filesystem->getModelSourcePath($model, $path);
201-
}
202-
203-
public function getBladePagePath(string $path = ''): string
204-
{
205-
return $this->filesystem->getBladePagePath($path);
206-
}
207-
208-
public function getMarkdownPagePath(string $path = ''): string
209-
{
210-
return $this->filesystem->getMarkdownPagePath($path);
211-
}
212-
213-
public function getMarkdownPostPath(string $path = ''): string
214-
{
215-
return $this->filesystem->getMarkdownPostPath($path);
216-
}
217-
218-
public function getDocumentationPagePath(string $path = ''): string
219-
{
220-
return $this->filesystem->getDocumentationPagePath($path);
221-
}
222-
223-
public function getSiteOutputPath(string $path = ''): string
224-
{
225-
return $this->filesystem->getSiteOutputPath($path);
226-
}
227-
228-
public function pathToRelative(string $path): string
229-
{
230-
return $this->filesystem->pathToRelative($path);
231-
}
232-
233134
/**
234135
* @inheritDoc
235136
*
@@ -245,4 +146,11 @@ public function toArray(): array
245146
'routes' => $this->routes(),
246147
];
247148
}
149+
150+
protected function needsToBeBooted(): void
151+
{
152+
if (! $this->booted) {
153+
$this->boot();
154+
}
155+
}
248156
}

0 commit comments

Comments
 (0)