From 305b038a8e0594dcd7ae2a6e89e72450a52b6843 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:22:14 +0200 Subject: [PATCH 01/19] Create Feature.php --- packages/framework/src/Enums/Feature.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/framework/src/Enums/Feature.php diff --git a/packages/framework/src/Enums/Feature.php b/packages/framework/src/Enums/Feature.php new file mode 100644 index 00000000000..9cbbf73cb1b --- /dev/null +++ b/packages/framework/src/Enums/Feature.php @@ -0,0 +1,8 @@ + Date: Tue, 9 Apr 2024 14:23:37 +0200 Subject: [PATCH 02/19] Add strict types declaration --- packages/framework/src/Enums/Feature.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Enums/Feature.php b/packages/framework/src/Enums/Feature.php index 9cbbf73cb1b..dff72ea3770 100644 --- a/packages/framework/src/Enums/Feature.php +++ b/packages/framework/src/Enums/Feature.php @@ -1,5 +1,7 @@ Date: Tue, 9 Apr 2024 14:23:56 +0200 Subject: [PATCH 03/19] Add enum description --- packages/framework/src/Enums/Feature.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Enums/Feature.php b/packages/framework/src/Enums/Feature.php index dff72ea3770..0856e3b7b71 100644 --- a/packages/framework/src/Enums/Feature.php +++ b/packages/framework/src/Enums/Feature.php @@ -4,6 +4,11 @@ namespace Hyde\Enums; +/** + * A configurable feature that belongs to the Features class. + * + * @see \Hyde\Facades\Features + */ enum Feature { // From 0db729d3cac5eca3fee13c6af669a65564ba2bac Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:24:22 +0200 Subject: [PATCH 04/19] Convert enum to backed enum --- packages/framework/src/Enums/Feature.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Enums/Feature.php b/packages/framework/src/Enums/Feature.php index 0856e3b7b71..f1044cec581 100644 --- a/packages/framework/src/Enums/Feature.php +++ b/packages/framework/src/Enums/Feature.php @@ -9,7 +9,7 @@ * * @see \Hyde\Facades\Features */ -enum Feature +enum Feature: string { // } From d9479bf6cc00f03e3e81146054335f6d0cc30d70 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:24:36 +0200 Subject: [PATCH 05/19] Add enum cases --- packages/framework/src/Enums/Feature.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Enums/Feature.php b/packages/framework/src/Enums/Feature.php index f1044cec581..073ef90f2f8 100644 --- a/packages/framework/src/Enums/Feature.php +++ b/packages/framework/src/Enums/Feature.php @@ -11,5 +11,17 @@ */ enum Feature: string { - // + // Page Modules + case HtmlPages = 'html-pages'; + case MarkdownPosts = 'markdown-posts'; + case BladePages = 'blade-pages'; + case MarkdownPages = 'markdown-pages'; + case DocumentationPages = 'documentation-pages'; + + // Frontend Features + case Darkmode = 'darkmode'; + case DocumentationSearch = 'documentation-search'; + + // Integrations + case Torchlight = 'torchlight'; } From c17a7df1ba59fda6da274464b915129fdf567069 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:27:50 +0200 Subject: [PATCH 06/19] Update features facade to use enum values --- packages/framework/src/Facades/Features.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 0a201cf8b22..7db0b5fe424 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -5,6 +5,7 @@ namespace Hyde\Facades; use Hyde\Hyde; +use Hyde\Enums\Feature; use Hyde\Pages\MarkdownPost; use Hyde\Pages\DocumentationPage; use Hyde\Support\Concerns\Serializable; @@ -104,42 +105,42 @@ public static function hasTorchlight(): bool public static function htmlPages(): string { - return 'html-pages'; + return Feature::HtmlPages->value; } public static function bladePages(): string { - return 'blade-pages'; + return Feature::BladePages->value; } public static function markdownPages(): string { - return 'markdown-pages'; + return Feature::MarkdownPages->value; } public static function markdownPosts(): string { - return 'markdown-posts'; + return Feature::MarkdownPosts->value; } public static function documentationPages(): string { - return 'documentation-pages'; + return Feature::DocumentationPages->value; } public static function documentationSearch(): string { - return 'documentation-search'; + return Feature::DocumentationSearch->value; } public static function darkmode(): string { - return 'darkmode'; + return Feature::Darkmode->value; } public static function torchlight(): string { - return 'torchlight'; + return Feature::Torchlight->value; } // ==================================================== From a43c18c85a287a0fc1415782c9d1f17f7fce73ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:32:40 +0200 Subject: [PATCH 07/19] Update mocking helper to take feature instance --- .../src/Framework/Concerns/Internal/MockableFeatures.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Concerns/Internal/MockableFeatures.php b/packages/framework/src/Framework/Concerns/Internal/MockableFeatures.php index 02cee0f71aa..13269050a4e 100644 --- a/packages/framework/src/Framework/Concerns/Internal/MockableFeatures.php +++ b/packages/framework/src/Framework/Concerns/Internal/MockableFeatures.php @@ -4,6 +4,8 @@ namespace Hyde\Framework\Concerns\Internal; +use Hyde\Enums\Feature; + use function is_array; /** @@ -30,8 +32,12 @@ public static function mock(string|array $feature, ?bool $enabled = null): void static::$mockedInstances[$feature] = $enabled; } - public static function resolveMockedInstance(string $feature): ?bool + public static function resolveMockedInstance(Feature|string $feature): ?bool { + if ($feature instanceof Feature) { + $feature = $feature->value; + } + return static::$mockedInstances[$feature] ?? null; } From 91217f514af3bb72d7e0337ef4a37c27477fc57e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:36:41 +0200 Subject: [PATCH 08/19] Update enabled method to take feature instance --- packages/framework/src/Facades/Features.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 7db0b5fe424..d9c4553e8f1 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -40,7 +40,7 @@ class Features implements SerializableContract /** * Determine if the given specified is enabled. */ - public static function enabled(string $feature): bool + public static function enabled(Feature|string $feature): bool { return static::resolveMockedInstance($feature) ?? in_array( $feature, Config::getArray('hyde.features', static::getDefaultOptions()) From d0812278833725dad790371538883265cc3a7227 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 8 Apr 2024 19:05:15 +0200 Subject: [PATCH 09/19] Update command to use features enum --- packages/framework/src/Console/Commands/DebugCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Console/Commands/DebugCommand.php b/packages/framework/src/Console/Commands/DebugCommand.php index c3f4effc11e..b722fb70bcb 100644 --- a/packages/framework/src/Console/Commands/DebugCommand.php +++ b/packages/framework/src/Console/Commands/DebugCommand.php @@ -70,11 +70,11 @@ protected function printVerbosePathInformation(): void protected function printEnabledFeatures(): void { - /** @var array $features */ + /** @var array<\Hyde\Enums\Feature> $features */ $features = Config::getArray('hyde.features', []); foreach ($features as $feature) { - $this->line(" - $feature"); + $this->line(" - $feature->name"); } } } From c42770e72b96f58d09bfb3affa05173beaf35c89 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:46:27 +0200 Subject: [PATCH 10/19] Update kernel helper to support features enum --- packages/framework/src/Foundation/HydeKernel.php | 5 +++-- packages/framework/src/Hyde.php | 3 ++- packages/framework/tests/Feature/HydeKernelTest.php | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Foundation/HydeKernel.php b/packages/framework/src/Foundation/HydeKernel.php index 8d5195b2de7..f880c5f98ce 100644 --- a/packages/framework/src/Foundation/HydeKernel.php +++ b/packages/framework/src/Foundation/HydeKernel.php @@ -4,6 +4,7 @@ namespace Hyde\Foundation; +use Hyde\Enums\Feature; use Hyde\Facades\Features; use Hyde\Foundation\Kernel\Filesystem; use Hyde\Foundation\Kernel\Hyperlinks; @@ -89,9 +90,9 @@ public function features(): Features return new Features; } - public function hasFeature(string $feature): bool + public function hasFeature(Feature|string $feature): bool { - return Features::enabled($feature); + return Features::enabled(is_string($feature) ? Feature::from($feature) : $feature); } /** @inheritDoc */ diff --git a/packages/framework/src/Hyde.php b/packages/framework/src/Hyde.php index 131db5b0f5b..c41b4d1415d 100644 --- a/packages/framework/src/Hyde.php +++ b/packages/framework/src/Hyde.php @@ -4,6 +4,7 @@ namespace Hyde; +use Hyde\Enums\Feature; use Hyde\Facades\Features; use Hyde\Foundation\HydeKernel; use Hyde\Foundation\Kernel\FileCollection; @@ -58,7 +59,7 @@ * @method static HydeKernel getInstance() * @method static Filesystem filesystem() * @method static array getRegisteredExtensions() - * @method static bool hasFeature(string $feature) + * @method static bool hasFeature(Feature|string $feature) * @method static bool hasSiteUrl() * @method static void setInstance(HydeKernel $instance) * @method static void setBasePath(string $basePath) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index d692b601273..9c64381888b 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use Throwable; +use Hyde\Enums\Feature; use Composer\InstalledVersions; use Hyde\Facades\Features; use Hyde\Foundation\Facades\Pages; @@ -76,7 +77,8 @@ public function testFeaturesHelperReturnsNewFeaturesInstance() public function testHasFeatureHelperCallsMethodOnFeaturesClass() { - $this->assertSame(Features::enabled('foo'), Hyde::hasFeature('foo')); + $this->assertSame(Features::enabled(Feature::BladePages), Hyde::hasFeature(Feature::BladePages)); + $this->assertSame(Features::enabled(Feature::BladePages), Hyde::hasFeature('blade-pages')); } public function testCurrentPageHelperReturnsCurrentPageName() From c5adfa890cc915e3437e545948109e289c41272b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 14:39:02 +0200 Subject: [PATCH 11/19] Update feature flag methods to return feature enum instances --- packages/framework/src/Facades/Features.php | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index d9c4553e8f1..358bb2b90e5 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -103,44 +103,44 @@ public static function hasTorchlight(): bool // Configure features to be used in the config file. // ================================================= - public static function htmlPages(): string + public static function htmlPages(): Feature { - return Feature::HtmlPages->value; + return Feature::HtmlPages; } - public static function bladePages(): string + public static function bladePages(): Feature { - return Feature::BladePages->value; + return Feature::BladePages; } - public static function markdownPages(): string + public static function markdownPages(): Feature { - return Feature::MarkdownPages->value; + return Feature::MarkdownPages; } - public static function markdownPosts(): string + public static function markdownPosts(): Feature { - return Feature::MarkdownPosts->value; + return Feature::MarkdownPosts; } - public static function documentationPages(): string + public static function documentationPages(): Feature { - return Feature::DocumentationPages->value; + return Feature::DocumentationPages; } - public static function documentationSearch(): string + public static function documentationSearch(): Feature { - return Feature::DocumentationSearch->value; + return Feature::DocumentationSearch; } - public static function darkmode(): string + public static function darkmode(): Feature { - return Feature::Darkmode->value; + return Feature::Darkmode; } - public static function torchlight(): string + public static function torchlight(): Feature { - return Feature::Torchlight->value; + return Feature::Torchlight; } // ==================================================== From 63c63a366eacc132f558d2ae3ba723bd67fd533d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:01:00 +0200 Subject: [PATCH 12/19] Update weirdly written test --- .../tests/Feature/ConfigurableFeaturesTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Feature/ConfigurableFeaturesTest.php b/packages/framework/tests/Feature/ConfigurableFeaturesTest.php index 897236a50da..a7ce65f0e84 100644 --- a/packages/framework/tests/Feature/ConfigurableFeaturesTest.php +++ b/packages/framework/tests/Feature/ConfigurableFeaturesTest.php @@ -29,15 +29,13 @@ public function testHasFeatureReturnsTrueWhenFeatureIsEnabled() { $features = []; foreach (get_class_methods(Features::class) as $method) { - if (! str_starts_with($method, 'has') && $method !== 'enabled') { - $features[] = '\Hyde\Framework\Helpers\Features::'.$method.'()'; + if (str_starts_with($method, 'has') && $method !== 'hasDocumentationSearch' && $method !== 'hasTorchlight') { + $features[] = $method; } } - Config::set('hyde.features', $features); - - foreach ($features as $feature) { - $this->assertTrue(Features::enabled($feature), 'Method '.$feature.' should return true when feature is enabled'); + foreach ($features as $method) { + $this->assertTrue(Features::$method(), 'Method '.$method.' should return true when feature is enabled'); } } From c953142e2a7d25695527a96551b3be1ae1d22034 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:02:32 +0200 Subject: [PATCH 13/19] Update enabled method to only take feature instance --- packages/framework/src/Facades/Features.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 358bb2b90e5..77a1a0645fd 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -40,9 +40,9 @@ class Features implements SerializableContract /** * Determine if the given specified is enabled. */ - public static function enabled(Feature|string $feature): bool + public static function enabled(Feature $feature): bool { - return static::resolveMockedInstance($feature) ?? in_array( + return static::resolveMockedInstance($feature->value) ?? in_array( $feature, Config::getArray('hyde.features', static::getDefaultOptions()) ); } From a1fac0b1516a9143c5ad1f107d386699ea172b6e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:05:20 +0200 Subject: [PATCH 14/19] Deprecate static feature flag methods in favour of enum usage --- packages/framework/src/Facades/Features.php | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 77a1a0645fd..d4e6d0eafa3 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -103,41 +103,65 @@ public static function hasTorchlight(): bool // Configure features to be used in the config file. // ================================================= + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. + */ public static function htmlPages(): Feature { return Feature::HtmlPages; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. + */ public static function bladePages(): Feature { return Feature::BladePages; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. + */ public static function markdownPages(): Feature { return Feature::MarkdownPages; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. + */ public static function markdownPosts(): Feature { return Feature::MarkdownPosts; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. + */ public static function documentationPages(): Feature { return Feature::DocumentationPages; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. + */ public static function documentationSearch(): Feature { return Feature::DocumentationSearch; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. + */ public static function darkmode(): Feature { return Feature::Darkmode; } + /** + * @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. + */ public static function torchlight(): Feature { return Feature::Torchlight; From 04c6c703382ad9255c7e60b4ea6f85b6ae7b5fb2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:09:34 +0200 Subject: [PATCH 15/19] Add deprecation attributes to ease refactors --- packages/framework/src/Facades/Features.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index d4e6d0eafa3..d2d80599abb 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -8,6 +8,7 @@ use Hyde\Enums\Feature; use Hyde\Pages\MarkdownPost; use Hyde\Pages\DocumentationPage; +use JetBrains\PhpStorm\Deprecated; use Hyde\Support\Concerns\Serializable; use Hyde\Support\Contracts\SerializableContract; use Hyde\Framework\Concerns\Internal\MockableFeatures; @@ -106,6 +107,7 @@ public static function hasTorchlight(): bool /** * @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::HtmlPages Enum case', replacement: 'Feature::HtmlPages', since: '1.6.0')] public static function htmlPages(): Feature { return Feature::HtmlPages; @@ -114,6 +116,7 @@ public static function htmlPages(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::BladePages Enum case', replacement: 'Feature::BladePages', since: '1.6.0')] public static function bladePages(): Feature { return Feature::BladePages; @@ -122,6 +125,7 @@ public static function bladePages(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPages Enum case', replacement: 'Feature::MarkdownPages', since: '1.6.0')] public static function markdownPages(): Feature { return Feature::MarkdownPages; @@ -130,6 +134,7 @@ public static function markdownPages(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPosts Enum case', replacement: 'Feature::MarkdownPosts', since: '1.6.0')] public static function markdownPosts(): Feature { return Feature::MarkdownPosts; @@ -138,6 +143,7 @@ public static function markdownPosts(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationPages Enum case', replacement: 'Feature::DocumentationPages', since: '1.6.0')] public static function documentationPages(): Feature { return Feature::DocumentationPages; @@ -146,6 +152,7 @@ public static function documentationPages(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationSearch Enum case', replacement: 'Feature::DocumentationSearch', since: '1.6.0')] public static function documentationSearch(): Feature { return Feature::DocumentationSearch; @@ -154,6 +161,7 @@ public static function documentationSearch(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Darkmode Enum case', replacement: 'Feature::Darkmode', since: '1.6.0')] public static function darkmode(): Feature { return Feature::Darkmode; @@ -162,6 +170,7 @@ public static function darkmode(): Feature /** * @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. */ + #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Torchlight Enum case', replacement: 'Feature::Torchlight', since: '1.6.0')] public static function torchlight(): Feature { return Feature::Torchlight; From 53badd2828f8d2bfefc3e2a6683f102b427572bd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:10:04 +0200 Subject: [PATCH 16/19] Format deprecation notices --- packages/framework/src/Facades/Features.php | 32 ++++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index d2d80599abb..8daa02ebe77 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -104,72 +104,56 @@ public static function hasTorchlight(): bool // Configure features to be used in the config file. // ================================================= - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::HtmlPages` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::HtmlPages Enum case', replacement: 'Feature::HtmlPages', since: '1.6.0')] public static function htmlPages(): Feature { return Feature::HtmlPages; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::BladePages` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::BladePages Enum case', replacement: 'Feature::BladePages', since: '1.6.0')] public static function bladePages(): Feature { return Feature::BladePages; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPages` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPages Enum case', replacement: 'Feature::MarkdownPages', since: '1.6.0')] public static function markdownPages(): Feature { return Feature::MarkdownPages; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::MarkdownPosts` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::MarkdownPosts Enum case', replacement: 'Feature::MarkdownPosts', since: '1.6.0')] public static function markdownPosts(): Feature { return Feature::MarkdownPosts; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationPages` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationPages Enum case', replacement: 'Feature::DocumentationPages', since: '1.6.0')] public static function documentationPages(): Feature { return Feature::DocumentationPages; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::DocumentationSearch` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::DocumentationSearch Enum case', replacement: 'Feature::DocumentationSearch', since: '1.6.0')] public static function documentationSearch(): Feature { return Feature::DocumentationSearch; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::Darkmode` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Darkmode Enum case', replacement: 'Feature::Darkmode', since: '1.6.0')] public static function darkmode(): Feature { return Feature::Darkmode; } - /** - * @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. - */ + /** @deprecated This method will be removed in v2.0. Please use `Feature::Torchlight` instead. */ #[Deprecated(reason: 'Replaced by the \Hyde\Enums\Feature::Torchlight Enum case', replacement: 'Feature::Torchlight', since: '1.6.0')] public static function torchlight(): Feature { From 541dd0e24dbc245a32d7017ae65da3553732e64c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 16:57:28 +0200 Subject: [PATCH 17/19] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b06de39e4cf..be5ec17bfef 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -13,12 +13,13 @@ This serves two purposes: - Added a `@head` stack to the `head.blade.php` component in https://github.com/hydephp/develop/pull/1567 - Added a `Hyde::route()` helper to the `Hyde` facade in https://github.com/hydephp/develop/pull/1591 - Added new global helper functions (`asset()`, `route()`, `url()`) in https://github.com/hydephp/develop/pull/1592 +- Added a new `Feature` enum to improve the `Features` facade in https://github.com/hydephp/develop/pull/1650 ### Changed -- for changes in existing functionality. +- The `features` array in the `config/hyde.php` configuration file is now an array of `Feature` enums in https://github.com/hydephp/develop/pull/1650 ### Deprecated -- for soon-to-be removed features. +- Deprecated the static `Features` flag methods used in the configuration files in https://github.com/hydephp/develop/pull/1650 and will be removed in HydePHP v2.0 ### Removed - for now removed features. @@ -28,3 +29,31 @@ This serves two purposes: ### Security - in case of vulnerabilities. + +### Upgrade Path + +In order to prepare your project for HydePHP v2.0, you should update your `config/hyde.php` configuration file to use the new `Feature` enum for the `features` array. + +Your new config array should look like this: + +```php + use Hyde\Enums\Feature; + + 'features' => [ + // Page Modules + Feature::HtmlPages, + Feature::MarkdownPosts, + Feature::BladePages, + Feature::MarkdownPages, + Feature::DocumentationPages, + + // Frontend Features + Feature::Darkmode, + Feature::DocumentationSearch, + + // Integrations + Feature::Torchlight, + ], +``` + +If you need more help, you can see detailed upgrade instructions in the pull request https://github.com/hydephp/develop/pull/1650 From 2df16f7eb23d137d53a9fe3f28ad1f2d24edb98e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 17:07:13 +0200 Subject: [PATCH 18/19] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index be5ec17bfef..efadf4218a8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -37,8 +37,10 @@ In order to prepare your project for HydePHP v2.0, you should update your `confi Your new config array should look like this: ```php + // Make sure to import the new Feature enum at the top of the file use Hyde\Enums\Feature; + // Then replace your enabled features with the new Feature enum cases 'features' => [ // Page Modules Feature::HtmlPages, @@ -56,4 +58,4 @@ Your new config array should look like this: ], ``` -If you need more help, you can see detailed upgrade instructions in the pull request https://github.com/hydephp/develop/pull/1650 +If you need more help, you can see detailed upgrade instructions with screenshots in the pull request https://github.com/hydephp/develop/pull/1650 From 99e503c288bbb9d4fb304f3a3ae396cb183f4b86 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 9 Apr 2024 17:11:13 +0200 Subject: [PATCH 19/19] Replace deprecated method usages with feature enum cases --- config/hyde.php | 18 +++++------ packages/framework/config/hyde.php | 18 +++++------ packages/framework/src/Facades/Features.php | 32 +++++++++---------- .../Framework/Services/ValidationService.php | 3 +- .../tests/Feature/DarkmodeFeatureTest.php | 19 +++++------ 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 9cbbe1cceb3..333ba70b287 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -23,7 +23,7 @@ */ use Hyde\Facades\Author; -use Hyde\Facades\Features; +use Hyde\Enums\Feature; use Hyde\Facades\Meta; return [ @@ -254,18 +254,18 @@ 'features' => [ // Page Modules - Features::htmlPages(), - Features::markdownPosts(), - Features::bladePages(), - Features::markdownPages(), - Features::documentationPages(), + Feature::HtmlPages, + Feature::MarkdownPosts, + Feature::BladePages, + Feature::MarkdownPages, + Feature::DocumentationPages, // Frontend Features - Features::darkmode(), - Features::documentationSearch(), + Feature::Darkmode, + Feature::DocumentationSearch, // Integrations - Features::torchlight(), + Feature::Torchlight, ], /* diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 9cbbe1cceb3..333ba70b287 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -23,7 +23,7 @@ */ use Hyde\Facades\Author; -use Hyde\Facades\Features; +use Hyde\Enums\Feature; use Hyde\Facades\Meta; return [ @@ -254,18 +254,18 @@ 'features' => [ // Page Modules - Features::htmlPages(), - Features::markdownPosts(), - Features::bladePages(), - Features::markdownPages(), - Features::documentationPages(), + Feature::HtmlPages, + Feature::MarkdownPosts, + Feature::BladePages, + Feature::MarkdownPages, + Feature::DocumentationPages, // Frontend Features - Features::darkmode(), - Features::documentationSearch(), + Feature::Darkmode, + Feature::DocumentationSearch, // Integrations - Features::torchlight(), + Feature::Torchlight, ], /* diff --git a/packages/framework/src/Facades/Features.php b/packages/framework/src/Facades/Features.php index 8daa02ebe77..034108e5203 100644 --- a/packages/framework/src/Facades/Features.php +++ b/packages/framework/src/Facades/Features.php @@ -54,39 +54,39 @@ public static function enabled(Feature $feature): bool public static function hasHtmlPages(): bool { - return static::enabled(static::htmlPages()); + return static::enabled(Feature::HtmlPages); } public static function hasBladePages(): bool { - return static::enabled(static::bladePages()); + return static::enabled(Feature::BladePages); } public static function hasMarkdownPages(): bool { - return static::enabled(static::markdownPages()); + return static::enabled(Feature::MarkdownPages); } public static function hasMarkdownPosts(): bool { - return static::enabled(static::markdownPosts()); + return static::enabled(Feature::MarkdownPosts); } public static function hasDocumentationPages(): bool { - return static::enabled(static::documentationPages()); + return static::enabled(Feature::DocumentationPages); } public static function hasDocumentationSearch(): bool { - return static::enabled(static::documentationSearch()) + return static::enabled(Feature::DocumentationSearch) && static::hasDocumentationPages() && count(DocumentationPage::files()) > 0; } public static function hasDarkmode(): bool { - return static::enabled(static::darkmode()); + return static::enabled(Feature::Darkmode); } /** @@ -95,7 +95,7 @@ public static function hasDarkmode(): bool */ public static function hasTorchlight(): bool { - return static::enabled(static::torchlight()) + return static::enabled(Feature::Torchlight) && (Config::getNullableString('torchlight.token') !== null) && (app('env') !== 'testing'); } @@ -203,18 +203,18 @@ protected static function getDefaultOptions(): array { return [ // Page Modules - static::htmlPages(), - static::markdownPosts(), - static::bladePages(), - static::markdownPages(), - static::documentationPages(), + Feature::HtmlPages, + Feature::MarkdownPosts, + Feature::BladePages, + Feature::MarkdownPages, + Feature::DocumentationPages, // Frontend Features - static::darkmode(), - static::documentationSearch(), + Feature::Darkmode, + Feature::DocumentationSearch, // Integrations - static::torchlight(), + Feature::Torchlight, ]; } } diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index da7c0fa7db0..89486276ee8 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Services; use Hyde\Hyde; +use Hyde\Enums\Feature; use Hyde\Facades\Config; use Hyde\Facades\Features; use Hyde\Pages\BladePage; @@ -121,7 +122,7 @@ public function check_site_has_a_base_url_set(Result $result): Result public function check_a_torchlight_api_token_is_set(Result $result): Result { - if (! Features::enabled(Features::torchlight())) { + if (! Features::enabled(Feature::Torchlight)) { return $result->skip('Check a Torchlight API token is set') ->withTip('Torchlight is an API for code syntax highlighting. You can enable it in the Hyde config.'); } diff --git a/packages/framework/tests/Feature/DarkmodeFeatureTest.php b/packages/framework/tests/Feature/DarkmodeFeatureTest.php index a1d710d25bd..09f3c57f4b9 100644 --- a/packages/framework/tests/Feature/DarkmodeFeatureTest.php +++ b/packages/framework/tests/Feature/DarkmodeFeatureTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use Hyde\Enums\Feature; use Hyde\Facades\Features; use Hyde\Pages\DocumentationPage; use Hyde\Testing\TestCase; @@ -30,7 +31,7 @@ public function testHasDarkmode() $this->assertFalse(Features::hasDarkmode()); Config::set('hyde.features', [ - Features::darkmode(), + Feature::Darkmode, ]); $this->assertTrue(Features::hasDarkmode()); @@ -39,9 +40,9 @@ public function testHasDarkmode() public function testLayoutHasToggleButtonAndScriptWhenEnabled() { Config::set('hyde.features', [ - Features::markdownPages(), - Features::bladePages(), - Features::darkmode(), + Feature::MarkdownPages, + Feature::BladePages, + Feature::Darkmode, ]); $view = view('hyde::layouts/page')->with([ @@ -57,8 +58,8 @@ public function testLayoutHasToggleButtonAndScriptWhenEnabled() public function testDocumentationPageHasToggleButtonAndScriptWhenEnabled() { Config::set('hyde.features', [ - Features::documentationPages(), - Features::darkmode(), + Feature::DocumentationPages, + Feature::Darkmode, ]); view()->share('page', new DocumentationPage()); @@ -76,8 +77,8 @@ public function testDocumentationPageHasToggleButtonAndScriptWhenEnabled() public function testDarkModeThemeButtonIsHiddenInLayoutsWhenDisabled() { Config::set('hyde.features', [ - Features::markdownPages(), - Features::bladePages(), + Feature::MarkdownPages, + Feature::BladePages, ]); $view = view('hyde::layouts/page')->with([ @@ -93,7 +94,7 @@ public function testDarkModeThemeButtonIsHiddenInLayoutsWhenDisabled() public function testDarkModeThemeButtonIsHiddenInDocumentationPagesWhenDisabled() { Config::set('hyde.features', [ - Features::documentationPages(), + Feature::DocumentationPages, ]); view()->share('page', new DocumentationPage());