granam / boolean-enum
Enumeration with booleans only
1.1.0
2021-03-23 15:28 UTC
Requires
- php: >=7.1
- granam/boolean: ^3.2
- granam/scalar-enum: ^1.1
Requires (Dev)
- granam/exceptions-hierarchy: ^5.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^8.3
- roave/security-advisories: dev-master
README
Usage
Use enum
<?php use \Granam\BooleanEnum\BooleanEnum; $enum = BooleanEnum::getEnum(true); echo $enum->getValue(); // 1 var_dump($enum->getValue()); // (bool) true var_dump($enum->is(true)); // true var_dump($enum->is(false)); // false var_dump($enum->is(1)); // false var_dump($enum->is($enum)); // true
NULL is NULL, enum can not hold it
You can not create BooleanEnum with NULL value. Just use NULL directly for such value.
<?php try { \Granam\BooleanEnum\BooleanEnum::getEnum(null); } catch(\Granam\BooleanEnum\Exceptions\UnexpectedValueToConvert $unexpectedValueToConvert) { echo $unexpectedValueToConvert->getMessage(); // Expected boolean or object with __toString method on strict mode, got NULL }
Installation
composer.phar require granam/boolean-enum
or manually edit composer.json at your project and "require":
block (extend existing)
"require": { "granam/boolean-enum": "dev-master" }