for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace yiicod\base\models\enumerables\base;
/**
* Enumerable is the base class for all enumerable types.
*
* To define an enumerable type, extend Enumberable and define string constants.
* Each constant represents an enumerable value.
* The constant name must be the same as the constant value.
* For example,
* <pre>
* class TextAlign extends Enumerable
* {
* const Left='Left';
* const Right='Right';
* }
* </pre>
* Then, one can use the enumerable values such as TextAlign::Left and
* TextAlign::Right.
* @author Alexey Orlov <[email protected]>
*/
abstract class Enumerable
{
* Get label of the enumerable
* @static
* @param $value
* @return mixed
public static function get($value)
$list = static::data();
return isset($list[$value]) ? $list[$value] : $value;
}
* Get list of the enumerable
* @param array $exclude
* @return array
public static function listData(array $exclude = []): array
foreach ($exclude as $item) {
unset($list[$item]);
return $list;
* Check if value in into keys
* @return bool
public static function inKeys($value): bool
return in_array($value, array_keys(static::listData([])));
* Check if value in into values
public static function inValues($value): bool
abstract protected static function data(): array;