Skip to content

Commit db3d5f8

Browse files
committed
Breaking: Replace feature config helper methods with enum usages
1 parent 3568fe5 commit db3d5f8

File tree

8 files changed

+103
-97
lines changed

8 files changed

+103
-97
lines changed

RELEASE_NOTES.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This serves two purposes:
1515

1616
### Changed
1717
- **Breaking:** The internals of the navigation system has been rewritten into a new Navigation API. This change is breaking for custom navigation implementations. For more information, see below.
18+
- **Breaking:** The `hyde.features` configuration format has changed to use Enums instead of static method calls. For more information, see below.
1819
- Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573
1920
- Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.)
2021
- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566
@@ -70,6 +71,55 @@ The following configuration entries have been updated:
7071
- Changed configuration option `docs.table_of_contents` to `docs.sidebar.table_of_contents` in https://github.com/hydephp/develop/pull/1584
7172
- Upgrade path: Move the `table_of_contents` option's array in the `config/docs.php` file into the `sidebar` array in the same file.
7273

74+
### Features configuration changes
75+
76+
The `hyde.features` configuration format has changed to use Enums instead of static method calls. This change is breaking as it will require you to update your `config/hyde.php` file.
77+
78+
#### Instead of
79+
80+
```php
81+
// filepath: config/hyde.php
82+
83+
'features' => [
84+
// Page Modules
85+
Features::htmlPages(),
86+
Features::markdownPosts(),
87+
Features::bladePages(),
88+
Features::markdownPages(),
89+
Features::documentationPages(),
90+
91+
// Frontend Features
92+
Features::darkmode(),
93+
Features::documentationSearch(),
94+
95+
// Integrations
96+
Features::torchlight(),
97+
],
98+
```
99+
100+
#### Use instead
101+
102+
```php
103+
// filepath: config/hyde.php
104+
105+
'features' => [
106+
// Page Modules
107+
Feature::HtmlPages,
108+
Feature::MarkdownPosts,
109+
Feature::BladePages,
110+
Feature::MarkdownPages,
111+
Feature::DocumentationPages,
112+
113+
// Frontend Features
114+
Feature::Darkmode,
115+
Feature::DocumentationSearch,
116+
117+
// Integrations
118+
Feature::Torchlight,
119+
],
120+
```
121+
122+
Of course, if you have disabled any of the features, do not include them in the new array.
73123

74124
## General impact
75125

config/hyde.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424

2525
use Hyde\Facades\Author;
26-
use Hyde\Facades\Features;
2726
use Hyde\Facades\Meta;
27+
use Hyde\Foundation\Concerns\Feature;
2828

2929
return [
3030

@@ -248,24 +248,23 @@
248248
|
249249
| Some of Hyde's features are optional. Feel free to disable the features
250250
| you don't need by removing or commenting them out from this array.
251-
| This config concept is directly inspired by Laravel Jetstream.
252251
|
253252
*/
254253

255254
'features' => [
256255
// Page Modules
257-
Features::htmlPages(),
258-
Features::markdownPosts(),
259-
Features::bladePages(),
260-
Features::markdownPages(),
261-
Features::documentationPages(),
256+
Feature::HtmlPages,
257+
Feature::MarkdownPosts,
258+
Feature::BladePages,
259+
Feature::MarkdownPages,
260+
Feature::DocumentationPages,
262261

263262
// Frontend Features
264-
Features::darkmode(),
265-
Features::documentationSearch(),
263+
Feature::Darkmode,
264+
Feature::DocumentationSearch,
266265

267266
// Integrations
268-
Features::torchlight(),
267+
Feature::Torchlight,
269268
],
270269

271270
/*

docs/creating-content/documentation-pages.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ that runs during the build command, and a frontend JavaScript plugin that adds t
290290

291291
>info Tip: The HydeSearch plugin is what powers the search feature on this site! Why not [try it out](search)?
292292

293-
The search feature is enabled by default. You can disable it by removing the `documentationSearch` from the Hyde `Features` config array.
293+
The search feature is enabled by default. You can disable it by removing the `DocumentationSearch` option from the Hyde `Features` config array.
294294

295295
```php
296296
// filepath: config/hyde.php
297297
'features' => [
298-
Features::documentationSearch(), // [tl! --]
298+
Feature::DocumentationSearch, // [tl! --]
299299
],
300300
```
301301

packages/framework/config/hyde.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424

2525
use Hyde\Facades\Author;
26-
use Hyde\Facades\Features;
2726
use Hyde\Facades\Meta;
27+
use Hyde\Foundation\Concerns\Feature;
2828

2929
return [
3030

@@ -248,24 +248,23 @@
248248
|
249249
| Some of Hyde's features are optional. Feel free to disable the features
250250
| you don't need by removing or commenting them out from this array.
251-
| This config concept is directly inspired by Laravel Jetstream.
252251
|
253252
*/
254253

255254
'features' => [
256255
// Page Modules
257-
Features::htmlPages(),
258-
Features::markdownPosts(),
259-
Features::bladePages(),
260-
Features::markdownPages(),
261-
Features::documentationPages(),
256+
Feature::HtmlPages,
257+
Feature::MarkdownPosts,
258+
Feature::BladePages,
259+
Feature::MarkdownPages,
260+
Feature::DocumentationPages,
262261

263262
// Frontend Features
264-
Features::darkmode(),
265-
Features::documentationSearch(),
263+
Feature::Darkmode,
264+
Feature::DocumentationSearch,
266265

267266
// Integrations
268-
Features::torchlight(),
267+
Feature::Torchlight,
269268
],
270269

271270
/*

packages/framework/src/Facades/Features.php

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,82 +56,38 @@ public static function enabled(): array
5656
return Hyde::features()->features;
5757
}
5858

59-
// =================================================
60-
// Configure features to be used in the config file.
61-
// =================================================
62-
63-
public static function htmlPages(): Feature
64-
{
65-
return Feature::HtmlPages;
66-
}
67-
68-
public static function bladePages(): Feature
69-
{
70-
return Feature::BladePages;
71-
}
72-
73-
public static function markdownPages(): Feature
74-
{
75-
return Feature::MarkdownPages;
76-
}
77-
78-
public static function markdownPosts(): Feature
79-
{
80-
return Feature::MarkdownPosts;
81-
}
82-
83-
public static function documentationPages(): Feature
84-
{
85-
return Feature::DocumentationPages;
86-
}
87-
88-
public static function documentationSearch(): Feature
89-
{
90-
return Feature::DocumentationSearch;
91-
}
92-
93-
public static function darkmode(): Feature
94-
{
95-
return Feature::Darkmode;
96-
}
97-
98-
public static function torchlight(): Feature
99-
{
100-
return Feature::Torchlight;
101-
}
102-
10359
// ================================================
10460
// Determine if a given feature is enabled.
10561
// ================================================
10662

10763
public static function hasHtmlPages(): bool
10864
{
109-
return static::has(static::htmlPages());
65+
return static::has(Feature::HtmlPages);
11066
}
11167

11268
public static function hasBladePages(): bool
11369
{
114-
return static::has(static::bladePages());
70+
return static::has(Feature::BladePages);
11571
}
11672

11773
public static function hasMarkdownPages(): bool
11874
{
119-
return static::has(static::markdownPages());
75+
return static::has(Feature::MarkdownPages);
12076
}
12177

12278
public static function hasMarkdownPosts(): bool
12379
{
124-
return static::has(static::markdownPosts());
80+
return static::has(Feature::MarkdownPosts);
12581
}
12682

12783
public static function hasDocumentationPages(): bool
12884
{
129-
return static::has(static::documentationPages());
85+
return static::has(Feature::DocumentationPages);
13086
}
13187

13288
public static function hasDarkmode(): bool
13389
{
134-
return static::has(static::darkmode());
90+
return static::has(Feature::Darkmode);
13591
}
13692

13793
// ====================================================
@@ -167,14 +123,14 @@ public static function hasRss(): bool
167123
*/
168124
public static function hasTorchlight(): bool
169125
{
170-
return static::has(static::torchlight())
126+
return static::has(Feature::Torchlight)
171127
&& (Config::getNullableString('torchlight.token') !== null)
172128
&& (app('env') !== 'testing');
173129
}
174130

175131
public static function hasDocumentationSearch(): bool
176132
{
177-
return static::has(static::documentationSearch())
133+
return static::has(Feature::DocumentationSearch)
178134
&& static::hasDocumentationPages()
179135
&& count(DocumentationPage::files()) > 0;
180136
}

packages/framework/src/Framework/Services/ValidationService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Hyde\Pages\BladePage;
1111
use Hyde\Pages\MarkdownPage;
1212
use Hyde\Pages\DocumentationPage;
13+
use Hyde\Foundation\Concerns\Feature;
1314
use Hyde\Support\Models\ValidationResult as Result;
1415

1516
use function count;
@@ -121,7 +122,7 @@ public function check_site_has_a_base_url_set(Result $result): Result
121122

122123
public function check_a_torchlight_api_token_is_set(Result $result): Result
123124
{
124-
if (! Features::has(Features::torchlight())) {
125+
if (! Features::has(Feature::Torchlight)) {
125126
return $result->skip('Check a Torchlight API token is set')
126127
->withTip('Torchlight is an API for code syntax highlighting. You can enable it in the Hyde config.');
127128
}

packages/framework/tests/Feature/ConfigurableFeaturesTest.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Hyde\Hyde;
88
use Hyde\Facades\Features;
99
use Hyde\Testing\TestCase;
10+
use Hyde\Foundation\Concerns\Feature;
1011
use Illuminate\Support\Facades\Config;
1112

1213
use function config;
@@ -82,9 +83,9 @@ public function testToArrayMethodContainsAllSettings()
8283
public function testToArrayMethodContainsAllSettingsIncludingFalseValues()
8384
{
8485
config(['hyde.features' => [
85-
Features::htmlPages(),
86-
Features::markdownPosts(),
87-
Features::bladePages(),
86+
Feature::HtmlPages,
87+
Feature::MarkdownPosts,
88+
Feature::BladePages,
8889
]]);
8990

9091
$this->assertSame([
@@ -102,9 +103,9 @@ public function testToArrayMethodContainsAllSettingsIncludingFalseValues()
102103
public function testSerializedClassState()
103104
{
104105
config(['hyde.features' => [
105-
Features::htmlPages(),
106-
Features::markdownPosts(),
107-
Features::bladePages(),
106+
Feature::HtmlPages,
107+
Feature::MarkdownPosts,
108+
Feature::BladePages,
108109
]]);
109110

110111
$this->assertSame(<<<'JSON'
@@ -168,9 +169,9 @@ public function testGetEnabledUsesDefaultOptionsWhenConfigIsEmpty()
168169
public function testGetEnabledUsesConfiguredOptions()
169170
{
170171
config(['hyde.features' => [
171-
Features::htmlPages(),
172-
Features::markdownPosts(),
173-
Features::bladePages(),
172+
Feature::HtmlPages,
173+
Feature::MarkdownPosts,
174+
Feature::BladePages,
174175
]]);
175176

176177
$this->assertSame([
@@ -185,9 +186,9 @@ public function testCannotUseArbitraryValuesInEnabledOptions()
185186
$this->expectException(\TypeError::class); // Todo: Consider if we should handle this again by ignoring it, or throw with a more specific message
186187

187188
$config = [
188-
Features::htmlPages(),
189-
Features::markdownPosts(),
190-
Features::bladePages(),
189+
Feature::HtmlPages,
190+
Feature::MarkdownPosts,
191+
Feature::BladePages,
191192
'foo',
192193
];
193194

0 commit comments

Comments
 (0)