PHP Class MyCLabs\Enum\Enum

Create an enum by implementing this class and adding class constants.
Datei anzeigen Open project: myclabs/php-enum Class Usage Examples

Protected Properties

Property Type Description
$cache array Store existing constants in a static cache per object.
$value mixed Enum value

Public Methods

Method Description
__callStatic ( string $name, array $arguments ) : static Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
__construct ( mixed $value ) Creates a new value of some type
__toString ( ) : string
equals ( Enum $enum ) : boolean Compares one Enum with another.
getKey ( ) : mixed Returns the enum key (i.e. the constant name).
getValue ( ) : mixed
isValid ( $value ) : boolean Check if is valid enum value
isValidKey ( $key ) : boolean Check if is valid enum key
keys ( ) : array Returns the names (keys) of all constants in the Enum class
search ( $value ) : mixed Return key for value
toArray ( ) : array Returns all possible values as an array
values ( ) : static[] Returns instances of the Enum class of all Enum constants

Method Details

__callStatic() public static method

Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant
public static __callStatic ( string $name, array $arguments ) : static
$name string
$arguments array
return static

__construct() public method

Creates a new value of some type
public __construct ( mixed $value )
$value mixed

__toString() public method

public __toString ( ) : string
return string

equals() final public method

This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
final public equals ( Enum $enum ) : boolean
$enum Enum
return boolean True if Enums are equal, false if not equal

getKey() public method

Returns the enum key (i.e. the constant name).
public getKey ( ) : mixed
return mixed

getValue() public method

public getValue ( ) : mixed
return mixed

isValid() public static method

Check if is valid enum value
public static isValid ( $value ) : boolean
$value
return boolean

isValidKey() public static method

Check if is valid enum key
public static isValidKey ( $key ) : boolean
$key
return boolean

keys() public static method

Returns the names (keys) of all constants in the Enum class
public static keys ( ) : array
return array

toArray() public static method

Returns all possible values as an array
public static toArray ( ) : array
return array Constant name in key, constant value in value

values() public static method

Returns instances of the Enum class of all Enum constants
public static values ( ) : static[]
return static[] Constant name in key, Enum instance in value

Property Details

$cache protected_oe static_oe property

Store existing constants in a static cache per object.
protected static array $cache
return array

$value protected_oe property

Enum value
protected mixed $value
return mixed