granam / scalar-enum
Enumeration with scalar values
1.2.0
2021-03-24 16:45 UTC
Requires
- php: >=7.3
- granam/scalar: ^5.1
Requires (Dev)
- granam/exceptions-hierarchy: ^5.0
- granam/test-with-mockery: ^2.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.0
- roave/security-advisories: dev-master
README
Usage
Use enum
<?php $enum = \Granam\ScalarEnum\ScalarEnum::getEnum('foo bar'); echo $enum->getValue(); // foo bar var_dump($enum->is('foo bar')); // true
NULL is NULL, enum can not hold it
You can not create ScalarEnum with NULL value. Just use NULL directly for such value.
<?php try { \Granam\ScalarEnum\ScalarEnum::getEnum(null); } catch(\Granam\ScalarEnum\Exceptions\UnexpectedValueToEnum $unexpectedValueToEnum) { echo $unexpectedValueToEnum->getMessage(); // Expected scalar or object with __toString method on strict mode, got NULL }
Installation
composer.phar require granam/scalar-enum
or manually edit composer.json at your project and "require":
block (extend existing)
"require": { "granam/scalar-enum": "dev-master" }