Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a new Feature enum to improve the Features facade #1650

Merged
merged 20 commits into from
Apr 9, 2024

Conversation

caendesilva
Copy link
Member

@caendesilva caendesilva commented Apr 9, 2024

Abstract

Cherry picks some changes from #1647 and #1649 in order to make the v2 upgrade path smoother. See https://twitter.com/CodeWithCaen/status/1777647925939593341

Using Enums for this improves the type safety and IDE support. For example if you use Hyde::hasFeature() which now takes an enum instead of a string, your IDE will provide autocomplete and warn if you use a feature that is not supported by Hyde. Due to these simplifications the old static feature flag methods have been removed. To upgrade, replace the following method usages (where the array key is the old syntax and the value is the new)

use Hyde\Facades\Features;
use Hyde\Enums\Feature;

[
    Features::htmlPages()           => Feature::HtmlPages,
    Features::markdownPosts()       => Feature::MarkdownPosts,
    Features::bladePages()          => Feature::BladePages,
    Features::markdownPages()       => Feature::MarkdownPages,
    Features::documentationPages()  => Feature::DocumentationPages,
    Features::darkmode()            => Feature::Darkmode,
    Features::documentationSearch() => Feature::DocumentationSearch,
    Features::torchlight()          => Feature::Torchlight,
]

Upgrade Path

To upgrade to use the enum cases instead of the now deprecated static features methods, simply replace the following usages:

diff

PhpStorm Automatic Refactors

If you are using PhpStorm, you can follow these steps to do it automatically

Step 1: Put your caret on one of the deprecated method calls in the features array in the config/hyde.php file

1

Step 2: Run Alt+Enter to open the context menu

2

Step 3: On the highlighted option, press right arrow to open the submenu and "Fix all deprecated problems in file"

3

Step 4: Move the cursor to the added Feature class and open the context menu again

4

Step 5: Select the "Import class" option

5

Step 6: Done!

6

@caendesilva caendesilva force-pushed the introduce-a-new-feature-enum branch from 54c881c to a43c18c Compare April 9, 2024 12:35
@caendesilva caendesilva force-pushed the introduce-a-new-feature-enum branch from 6b1e4a8 to c5adfa8 Compare April 9, 2024 12:49
@caendesilva caendesilva changed the title Introduce a new feature enum Introduce a new Feature enum to improve the Features facade Apr 9, 2024
@caendesilva caendesilva force-pushed the introduce-a-new-feature-enum branch from 87762b2 to a1fac0b Compare April 9, 2024 14:06
@caendesilva caendesilva marked this pull request as ready for review April 9, 2024 15:12
@caendesilva caendesilva merged commit d5f410d into master Apr 9, 2024
19 checks passed
@caendesilva caendesilva deleted the introduce-a-new-feature-enum branch April 9, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant