fixmind / enum
Class organizes collections of constants. Gives the ability to keep code clear, transparent and strict.
1.0.2
2019-09-02 23:09 UTC
This package is auto-updated.
Last update: 2024-09-29 05:28:22 UTC
README
Class organizes collections of constants. Gives the ability to keep code clear, transparent and strict. Like the SplEnum class, but much better.
USAGE - two ways to define a collection
class Vertical extends Enum { const TOP = 'TOP'; const MIDDLE = 'MIDDLE'; const BOTTOM = 'BOTTOM'; } // OR class Horizontal extends Enum { const VALUE = ['LEFT', 'CENTER', 'RIGHT']; }
4 REASONS TO USE
1 REASON - use ENUM to extortion type of param method
class MyClass { public function __construct(Vertical $vertical) { } } new MyClass(Vertical::TOP());
2 USAGE - easy value compare
if (Vertical::TOP() == 'TOP') { if (Vertical::TOP()->is(Vertical::TOP)) { } }
3 USAGE - list of posibilitis
foreach(Vertical::getOptionList() as $option) { echo $option; }
4 USAGE - check if option exists
if (Vertical::isValid('TOP')) { echo 'TOP is a valid value of Vertical Enum'; } if (Vertical::isValid('LEFT') == false) { echo 'LEFT is not a valid value of Vertical Enum'; }