petrknap/enum
最新稳定版本:v3.0.1
Composer 安装命令:
composer require petrknap/enum
包简介
Enumerated type for PHP
README 文档
README
What is Enum?
In computer programming, an enumerated type (also called enumeration or enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but which are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily. -- Enumerated type - Wikipedia, The Free Encyclopedia
Why use Enums instead of Constants?
Because it is safer and less scary than using constants. Don't trust me? Let see at this code:
use PetrKnap\Enum\Readme\MyBoolean; $isTrue = function (int $myBoolean) { switch($myBoolean) { case MyBoolean::MY_TRUE: return true; case MyBoolean::MY_FALSE: return false; } }; var_dump($isTrue(MyBoolean::MY_TRUE)); // true - correct var_dump($isTrue(MyBoolean::MY_FALSE)); // false - correct var_dump($isTrue(0)); // none var_dump($isTrue(1)); // true - expected var_dump($isTrue(2)); // false var_dump($isTrue((int) true)); // true - expected var_dump($isTrue((int) false)); // none
And now the same code with enum instead of constants:
use PetrKnap\Enum\Readme\MyBoolean; $isTrue = function (MyBoolean $myBoolean): bool { switch($myBoolean) { case MyBoolean::MyTrue: return true; case MyBoolean::MyFalse: return false; } }; var_dump($isTrue(MyBoolean::MyTrue)); // true - correct var_dump($isTrue(MyBoolean::MyFalse)); // false - correct
Run composer require petrknap/enum to install it.
You can support this project via donation.
The project is licensed under the terms of the LGPL-3.0-or-later.
petrknap/enum 适用场景与选型建议
petrknap/enum 是一款 基于 Dockerfile 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「enum」 「enumerated」 「enumerated-types」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 petrknap/enum 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 petrknap/enum 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 petrknap/enum 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enums represent a set of predefined values. Useful for ensuring data consistency.
Enum type behavior for Yii2 based on class constants
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
Enum libraries used by Zimbra Api
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2023-10-17