Skip to content
/ enum Public

Class organizes collections of constants. Gives the ability to keep code clear, transparent and strict. Like the SplEnum class, but much better.

License

Notifications You must be signed in to change notification settings

fixmind/enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enum - missing type in PHP

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';
}

About

Class organizes collections of constants. Gives the ability to keep code clear, transparent and strict. Like the SplEnum class, but much better.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages