tailflow/enum
Composer 安装命令:
composer require tailflow/enum
包简介
PHP Enums
关键字:
README 文档
README
Introduction
The package offers strongly typed enums in PHP. In this package, enums are always objects, never constant values on their own. This allows for proper static analysis and refactoring in IDEs.
Installation
You can install the package via composer:
composer require tailflow/enum
Usage
Here is how enums are defined:
use Tailflow\Enum\Enum; class Status extends Enum { public const Inactive = 0; public const Active = 1; public const OnHold = 3; }
This is how they are used:
$class->setStatus(Status::Inactive);
Custom enum labels
By default, enum labels are derived from the constant names. To get enum label, you can use ::getLabel method on enum class:
// $label will be equal to "OnHold" - the name of the constant $label = Status::getLabel(Status::OnHold);
Optionally, you can provide a different label for any given enum value:
use Tailflow\Enum\Enum; class Status extends Enum { public const Inactive = 0; public const Active = 1; public const OnHold = 3; public static function labels(): array { return [ self::OnHold => 'waiting' ]; } } // $label will be equal to "waiting" - the custom label defined in "labels" method $label = Status::getLabel(Status::OnHold);
Listing all enum labels
To get a list of all labels of the enum, you can use ::getLabels method:
// $labels will contain the array - ['Inactive', 'Active', 'waiting'] $labels = Status::getLabels();
Listing all enum values
To get a list of all values of the enum, you can use ::getValues method:
// $labels will contain the array - [0, 1, 3] $labels = Status::getValues();
License
The Laravel Orion is open-source software licensed under the MIT license.
tailflow/enum 适用场景与选型建议
tailflow/enum 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.36k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「enum」 「enumerable」 「tailflow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tailflow/enum 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tailflow/enum 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tailflow/enum 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enum type behavior for Yii2 based on class constants
Automatically cast JSON columns to PHP objects in Laravel using Spatie's data-transfer-object class
A PHP Abstract Enum Class
Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
Enum type behavior and helper for Yii2, for PostgreSQL only
Litgroup enumerable doctrine type
统计信息
- 总下载量: 4.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-01