raid/core-enum
Composer 安装命令:
composer require raid/core-enum
包简介
Raid Core Enum
README 文档
README
This package is responsible for handling all enums in the system.
The package using the archtechx/enums package as a base for the enums.
Installation
composer require raid/core-enum
Configuration
php artisan core:publish-enum
Usage
class PostController extends Controller { /** * Invoke the controller method. */ public function __invoke(Request $request): JsonResponse { $adminType = UserTypeEnum::ADMIN; $guestType = UserTypeEnum::GUEST; $userType = UserTypeEnum::USER; $userTypeConstants = UserTypeEnum::constants(); $hasAdminConstant = UserTypeEnum::hasConstant('ADMIN'); } }
How to work this
Let's create our const enum class and prefer classes as they ar extendable.
You can use this command to create your enum class.
php artisan core:make-enum UserTypeEnum
<?php namespace App\Models\Enums; use Raid\Core\Enum\Models\Enum; class UserTypeEnum extends Enum { }
Let's add our constants.
<?php namespace App\Models\Enums; use Raid\Core\Enum\Models\Enum; class UserTypeEnum extends Enum { public const ADMIN = 'admin'; public const GUEST = 'guest'; public const USER = 'user'; }
Case Enum
You can create a case enum class, use this command to create the case enum class.
php artisan core:make-case-enum UserTypeEnum
<?php namespace App\Models\Enums; use Raid\Core\Enum\Traits\Enum\CaseEnum; enum UserTypeEnum { use CaseEnum; }
Let's add our constants.
<?php namespace App\Models\Enums; use Raid\Core\Enum\Traits\Enum\CaseEnum; enum UserTypeEnum: string { use CaseEnum; case ADMIN = 'admin'; case USER = 'user'; case GUEST = 'guest'; }
You can work with this class as archtechx/enums class.
Const Enum
You can create a cont enum class, use this command to create the case enum class.
php artisan core:make-cont-enum UserTypeEnum
<?php namespace App\Models\Enums; use Raid\Core\Enum\Traits\Enum\ContEnum; enum UserTypeEnum { use ContEnum; }
Let's add our constants.
<?php namespace App\Models\Enums; use Raid\Core\Enum\Traits\Enum\ContEnum; enum UserTypeEnum: string { use ContEnum; case ADMIN = 'admin'; case USER = 'user'; case GUEST = 'guest'; }
You can use these methods to work with const enums.
UserTypeEnum::constants()to get all constants as an array.UserTypeEnum::hasConstant('ADMIN')to check if the constant exists.
And that's it.
License
The MIT License (MIT). Please see License File for more information.
Credits
Security
If you discover any security-related issues, please email instead of using the issue tracker.
About Raid
Raid is a PHP framework created by Mohamed Khedr, and it is maintained by Mohamed Khedr.
Support Raid
Raid is an MIT-licensed open-source project. It's an independent project with its ongoing development made possible.
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-27