{"id":18696159,"url":"https://github.com/defstudio/enum-features","last_synced_at":"2025-04-12T07:30:53.783Z","repository":{"id":178435538,"uuid":"661856563","full_name":"defstudio/enum-features","owner":"defstudio","description":"A simple trait to enable a feature system using Enums","archived":false,"fork":false,"pushed_at":"2024-07-08T17:47:40.000Z","size":82,"stargazers_count":15,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-09T13:28:14.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/defstudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fabio-ivona","defstudio"],"custom":["https://paypal.me/bdmstore"]}},"created_at":"2023-07-03T20:17:46.000Z","updated_at":"2024-07-08T17:47:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"967af9d6-f5e7-421b-906f-2d6c319d720f","html_url":"https://github.com/defstudio/enum-features","commit_stats":null,"previous_names":["defstudio/enum-features"],"tags_count":8,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defstudio%2Fenum-features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defstudio%2Fenum-features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defstudio%2Fenum-features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defstudio%2Fenum-features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/defstudio","download_url":"https://codeload.github.com/defstudio/enum-features/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223502196,"owners_count":17155938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T11:17:23.302Z","updated_at":"2024-11-07T11:17:23.927Z","avatar_url":"https://github.com/defstudio.png","language":"PHP","funding_links":["https://github.com/sponsors/fabio-ivona","https://github.com/sponsors/defstudio","https://paypal.me/bdmstore","https://github.com/sponsors/defstudio)!"],"categories":[],"sub_categories":[],"readme":"# Enum Features\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/defstudio/enum-features.svg?style=flat-square)](https://packagist.org/packages/defstudio/enum-features)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/defstudio/enum-features/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/defstudio/enum-features/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/defstudio/enum-features/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/defstudio/enum-features/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/defstudio/enum-features.svg?style=flat-square)](https://packagist.org/packages/defstudio/enum-features)\n[![License](https://img.shields.io/packagist/l/defstudio/telegraph?style=flat\u0026cacheSeconds=3600)](https://packagist.org/packages/defstudio/enum-features)\n[![Twitter Follow](https://img.shields.io/twitter/follow/FabioIvona?label=Follow\u0026style=social)](https://twitter.com/FabioIvona?ref_src=twsrc%5Etfw)\n\nA simple trait to enable a feature system using Enums:\n\n```php\nif(AppFeature::welcome_email-\u003eactive()){\n    Mail::to($newUser)-\u003esend(new WelcomeEmail($newUser));\n}\n```\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require defstudio/enum-features\n```\n\n## Usage\n\nFeatures can be enabled on any enum by using the `DefinesFeatures` trait:\n\n```php\nuse DefStudio\\EnumFeatures\\EnumFeatures;\n\nenum AppFeature\n{\n    use DefinesFeatures; // ← simply add this \n\n    case multi_language;\n    case impersonate;\n    case welcome_email;\n    \n    /* Feature resolution */\n    \n    //with a single method:\n    protected function resolve(Authenticatable $user = null) {\n        match($this){\n            case self::multi_language =\u003e true,\n            case self::impersonate =\u003e $user-\u003eisAdmin(),\n            default =\u003e false;\n        }\n    }\n    \n    //or with a dedicated method:\n    \n    protected function resolveImpersonate(Authenticatable $user = null){\n        return $user-\u003eisSuperAdmin();\n    }\n}\n```\n\nand should be registered in your Provider\n\n```php\nclass AppServiceProvider extends ServiceProvider\n{\n    //..\n    \n    public function boot(): void {\n        AppFeature::defineFeatures();\n    }\n}\n```\n\n\nthen, in code, a feature could be checked to be enabled:\n\n```php\nif(AppFeature::multi_language-\u003eactive()){\n    //.. multi language specific code\n}\n```\n\nAn extensive documentation is available at\n\nhttps://docs.defstudio.it/enum-features\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. [Follow Us](https://twitter.com/FabioIvona) on Twitter for more updates about this package.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Fabio Ivona](https://github.com/defstudio)\n- [def:studio team](https://github.com/defstudio)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Support us\n\nWe at [def:studio](https://github.com/defstudio) strongly believe that open source is the foundation of all our business and we try to contribute to it by helping other projects to grow along with developing and maintaining our packages. You can support our work by sponsoring us on [github](https://github.com/sponsors/defstudio)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefstudio%2Fenum-features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefstudio%2Fenum-features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefstudio%2Fenum-features/lists"}