Download the PHP package youngsource/typed-enum without Composer
On this page you can find all versions of the php package youngsource/typed-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download youngsource/typed-enum
More information about youngsource/typed-enum
Files in youngsource/typed-enum
Package typed-enum
Short Description A small class allowing for typed enumerations.
License MIT
Informations about the package typed-enum
Typed Enumerations
Typed-enum is A simple, lightweight and efficient enumeration library. Type hint your enumerated options efficiently and strictly to eliminate unintended side effects and bugs introduced by typos.
How to use:
Download
Download with composer:
Extending from TypedEnum
Extend from TypedEnum and use any scalar constants to define the enumeration:
You can now create instances of Foo by using the __callstatic method based on the name of the constant:
Testing for equality
As a bonus, you can now use strict comparisons. TypedEnum guarantees there to be only one instance of the same enumerated value at runtime.
Return the actual value:
If your application depends on the value assigned to the enumeration, you can easily fetch it with the getValue() getter.
Resolve the enumeration
Resolve an enumeration based on its value. The resolve method will return all enumerations with the same value in the array.
Tips
IDE integration
You can easily use the power of you ide by simply adding @method tags in the docblock of your class like this:
Psalm
We built TypedEnum with psalm! With these powerful annotations, you can now hint the scalar value of the enumeration:
Easy Bug protection
Php 7.2 allows for protected constants, and 7.4 uses private ones. Use these features to protect against unintended side effects!
Developed by laudis