softbucket / enum
PHP Enum
1.0.7
2020-07-24 18:41 UTC
Requires
- php: >=5.6
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^5
README
Latest build status:
Github: https://github.com/softbucket/enum
Packagist: https://packagist.org/packages/softbucket/enum
Feel free to support me :D
What you're getting in this package
1. Simple
The softbucket implementation does not require constants to be defined.
<?php
use Softbucket\Enum\Enum;
/**
* @method static self AM()
* @method static self PM()
*/
class Meridiem extends Enum
{
}
2. Comparator Support ===
and ==
Use PHP's natural comparator. This works by comparing objects references.
Meridiem::one() === Meridiem::one() //true
Meridiem::one() == Meridiem::one() //also true
3. Easy Parsing
Parsing a string into an enum is very easy.
$AMString = 'AM';
Meridiem::{$AMString}();
4. Helper utility methods
The Enum objects are clean of utility methods. Use EnumHelper to grab am array of Enums.
EnumHelper::allEnums(Meridiem::class);
EnumHelper::serialize($enum);
EnumHelper::unserialize($enumString);
Goodbye
Enum::getName()
Enum::fromName()
Enum::values()
Enum::getConstants()
5. Fast Enums
Using simple array caching.