ngabor84/enum
Composer 安装命令:
composer require ngabor84/enum
包简介
Enum is a simple implementation of php enumeration type.
README 文档
README
#Enum
About
Enum is a simple implementation of php's missing enumeration type.
Requirements
- PHP 7.0 or above
Installation
Install Enum via the composer package manager from packagist ngabor84/enum.
Usage
// Define a new Enum type class Status extends Enum { const ACTIVE = 'active'; const PASSIVE = 'pasive'; } // Use the new Status Enum type $carStatus = new Status(Status::ACTIVE); $carStatus->getValue(); // return 'active'; $carStatus2 = new Status(); $carStatus2->setValue(Status::PASSIVE); if ($carStatus2->isEqualTo($carStatus)) { // it will be false echo "\$carStatus2 and \$carStatus has the same value"; } else { // this will be printed echo "\$carStatus2 and \$carStatus has different value"; echo "\$carStatus2: $carStatus2"; // print '$carStatus2: passive' } Status::isValidValue('active'); // return true Status::isValidKey('INACTIVE'); // return false Status::getKeyByValue('passive'); // return 'PASSIVE' Status::listOptions(); // return ['ACTIVE' => 'active', 'PASSIVE' => 'passive'] Status::listKeys(); // return ['ACTIVE', 'PASSIVE'] Status::listValues(); // return ['active', 'passive'] Status::getDefaultValue(); // return 'active' (it's the first constants value by default, but this method is also overridable)
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-12