Class organizes collections of constants. Gives the ability to keep code clear, transparent and strict. Like the SplEnum class, but much better.
class Vertical extends Enum
{
const TOP = 'TOP';
const MIDDLE = 'MIDDLE';
const BOTTOM = 'BOTTOM';
}
// OR
class Horizontal extends Enum
{
const VALUE = ['LEFT', 'CENTER', 'RIGHT'];
}
class MyClass
{
public function __construct(Vertical $vertical)
{
}
}
new MyClass(Vertical::TOP());
if (Vertical::TOP() == 'TOP')
{
if (Vertical::TOP()->is(Vertical::TOP))
{
}
}
foreach(Vertical::getOptionList() as $option)
{
echo $option;
}
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';
}