xgbnl / enum
Laravel-based Enum Component.
dev-main
2023-12-06 03:51 UTC
Requires
- php: ^8.3.0
Requires (Dev)
- illuminate/console: v10.14.1
- illuminate/support: v10.14.1
- phpunit/phpunit: ^10.2
- symfony/var-dumper: ^6.3
This package is auto-updated.
Last update: 2024-11-06 05:43:36 UTC
README
Install
composer require xgbnl/enum dev-main
Simple
Create enum.
php artisan make:enum TestEnum
Define your Enums
use Elephant\Enums\Attributes\Description; use Elephant\Enums\Contacts\Descriptor; use Elephant\Enums\Contacts\Converter; use Elephant\Enums\Contacts\Enumerable; use Elephant\Enums\Traits\Convert; use Elephant\Enums\Traits\GetsAttributes; use Elephant\Enums\Traits\HasMethods; Enums TestEnum:string implements Enumserable,Converter,Descriptor { use HasMethods,GetsAttributes,Convert; #[Description('my_foo')] case Foo = 'foo'; #[Description('my_bar')] case Bar = 'bar'; }
Method
\Elephant\Test\Unit\TestEnum::Bar->description(); // 'my_bar' \Elephant\Test\Unit\TestEnum::Bar->convert(); // ['name' => 'Bar' 'value' => 'bar'] // ... more method. \Elephant\Test\Unit\TestEnum::options(); \Elephant\Test\Unit\TestEnum::names(); \Elephant\Test\Unit\TestEnum::values();
License
MIT