patr1k/phenum
Composer 安装命令:
composer require patr1k/phenum
包简介
PHP Enumerator
README 文档
README
How It Works
Unlike most enumerators which use an abstract class as a domain container, Phenum is a trait which can be attached to any class where the enumerated domain is expressed as constants.
Advantages
- By representing enums using scalar constants rather than objects, this approach is slightly faster and more memory efficient than OO-based approaches.
- Enums are more tightly coupled with the class to which they belong, which can make the code easier to read for developers who are new to your project.
Disadvantages
- Without using objects to represent enums, the auto-complete feature in your IDE won't know what the possible enum values are for a given domain. You would need to know which class defines the domain values, then begin typing the domain prefix to see the possible values.
<?php use Patr1k\Phenum; class Person { use Phenum\Enum; /** * @var string */ protected $gender; const GENDER_MALE = 'M'; const GENDER_FEMALE = 'F'; const GENDER_UNSPECIFIED = 'U'; /** * @return string */ public function getGender() { return $this->gender; } /** * @param string $gender * @throws Phenum\DomainException */ public function setGender($gender) { $this->gender = self::validateEnum($gender, 'GENDER'); } }
Requirements
- PHP >= 5.6.0
License
MIT License see LICENSE file
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-11