PHP code example of defstudio / enum-features

1. Go to this page and download the library: Download defstudio/enum-features library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

defstudio / enum-features example snippets


if(AppFeature::welcome_email->active()){
    Mail::to($newUser)->send(new WelcomeEmail($newUser));
}

use DefStudio\EnumFeatures\EnumFeatures;

enum AppFeature
{
    use DefinesFeatures; // ← simply add this 

    case multi_language;
    case impersonate;
    case welcome_email;
    
    /* Feature resolution */
    
    //with a single method:
    protected function resolve(Authenticatable $user = null) {
        match($this){
            case self::multi_language => true,
            case self::impersonate => $user->isAdmin(),
            default => false;
        }
    }
    
    //or with a dedicated method:
    
    protected function resolveImpersonate(Authenticatable $user = null){
        return $user->isSuperAdmin();
    }
}

class AppServiceProvider extends ServiceProvider
{
    //..
    
    public function boot(): void {
        AppFeature::defineFeatures();
    }
}

if(AppFeature::multi_language->active()){
    //.. multi language specific code
}