-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extracted feature flags into provider
- Loading branch information
1 parent
06c9dd5
commit a702275
Showing
4 changed files
with
101 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Laravel\Pennant\Feature; | ||
|
||
/** | ||
* Service provider for managing feature flags. | ||
* | ||
* This provider handles the definition and configuration of feature flags | ||
* used throughout the application. It allows for centralized management | ||
* of features that can be dynamically enabled or disabled. | ||
* | ||
* For more information on how to use and manage feature flags, please refer to: | ||
* | ||
* @see https://docs.vanguardbackup.com/experiments | ||
*/ | ||
class FeatureServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* This method is called by Laravel during the service provider registration | ||
* process. It's used to bind things in the service container. | ||
*/ | ||
public function register(): void | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* This method is called after all other service providers have been registered. | ||
* It's used to perform any boot-time operations or register event listeners. | ||
*/ | ||
public function boot(): void | ||
{ | ||
$this->defineFeatures(); | ||
} | ||
|
||
/** | ||
* Define feature flags with additional metadata. | ||
* | ||
* This method sets up feature flags and their associated metadata. | ||
* It iterates through the defined features, setting up each feature | ||
* with Laravel Pennant and storing its metadata in the config. | ||
* | ||
* Features can be toggled via the Experiments manager in user settings. | ||
*/ | ||
private function defineFeatures(): void | ||
{ | ||
$features = $this->getFeatures(); | ||
|
||
foreach ($features as $key => $metadata) { | ||
Feature::define($key, fn (): bool => $this->isFeatureEnabled()); | ||
config(["features.{$key}" => $metadata]); | ||
} | ||
} | ||
|
||
/** | ||
* Get the list of features with their metadata. | ||
* | ||
* This method returns an array of feature definitions. Each feature | ||
* is defined with a key and an array of metadata including title, | ||
* description, group, and icon. | ||
* | ||
* @return array<string, array{title: string, description: string, group: string, icon: string}> | ||
*/ | ||
private function getFeatures(): array | ||
{ | ||
return [ | ||
// 'example-feature' => [ | ||
// 'title' => 'Example Feature', | ||
// 'description' => 'Description of the example feature.', | ||
// 'group' => 'General', | ||
// 'icon' => 'heroicon-o-beaker', | ||
// ], | ||
]; | ||
} | ||
|
||
/** | ||
* Determine if a feature is enabled. | ||
* | ||
* This method checks whether a specific feature is enabled. | ||
* The implementation of this method should include the logic | ||
* to determine the state of each feature. | ||
* | ||
* @return bool True if the feature is enabled, false otherwise | ||
*/ | ||
private function isFeatureEnabled(): bool | ||
{ | ||
return false; | ||
// Default to disabled | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
<?php | ||
|
||
/** | ||
* Application Service Providers | ||
* | ||
* This array lists the service providers that will be loaded as part of the application bootstrap process. | ||
* Each provider is responsible for binding services in the container, registering events, or performing any other tasks. | ||
*/ | ||
|
||
return [ | ||
App\Providers\AppServiceProvider::class, | ||
App\Providers\FeatureServiceProvider::class, | ||
App\Providers\HorizonServiceProvider::class, | ||
App\Providers\VoltServiceProvider::class, | ||
App\Providers\ServerConnectionServiceProvider::class, | ||
App\Providers\VoltServiceProvider::class, | ||
Laravel\Sanctum\SanctumServiceProvider::class, | ||
]; |
Oops, something went wrong.