\MyCLabs\EnumEnum

Base Enum class

Create an enum by implementing this class and adding class constants.

Summary

Methods
Properties
Constants
__construct()
__wakeup()
from()
getValue()
getKey()
__toString()
equals()
keys()
values()
toArray()
isValid()
assertValidValue()
isValidKey()
search()
__callStatic()
jsonSerialize()
No public properties found
No constants found
No protected methods found
$value
$cache
$instances
N/A
assertValidValueReturningKey()
$key
N/A

Properties

$value

$value : mixed

Enum value

Type

mixed

$cache

$cache : array

Store existing constants in a static cache per object.

Type

array

$instances

$instances : array

Cache of instances of the Enum class

Type

array

$key

$key : string

Enum key, the constant name

Type

string

Methods

__construct()

__construct(mixed  $value) : mixed

Creates a new value of some type

Parameters

mixed $value

Throws

\UnexpectedValueException

if incompatible type is given.

Returns

mixed —

__wakeup()

__wakeup() : mixed

Returns

mixed —

from()

from(mixed  $value) : static

Parameters

mixed $value

Returns

static —

getValue()

getValue() : mixed

Returns

mixed —

getKey()

getKey() : string

Returns the enum key (i.e. the constant name).

Returns

string —

__toString()

__toString() : string

Returns

string —

equals()

equals(mixed  $variable = null) : bool

Determines if Enum should be considered equal with the variable passed as a parameter.

Returns false if an argument is an object of different class or not an object.

This method is final, for more information read https://github.com/myclabs/php-enum/issues/4

Parameters

mixed $variable

Returns

bool —

keys()

keys() : array

Returns the names (keys) of all constants in the Enum class

Returns

array —

values()

values() : static[]

Returns instances of the Enum class of all Enum constants

Returns

static[] —

Constant name in key, Enum instance in value

toArray()

toArray() : array

Returns all possible values as an array

Returns

array —

Constant name in key, constant value in value

isValid()

isValid( $value) : bool

Check if is valid enum value

Parameters

$value

Returns

bool —

assertValidValue()

assertValidValue(mixed  $value) : void

Asserts valid enum value

Parameters

mixed $value

isValidKey()

isValidKey( $key) : bool

Check if is valid enum key

Parameters

$key

Returns

bool —

search()

search(mixed  $value) : string|false

Return key for value

Parameters

mixed $value

Returns

string|false —

__callStatic()

__callStatic(string  $name, array  $arguments) : static

Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant

Parameters

string $name
array $arguments

Throws

\BadMethodCallException

Returns

static —

jsonSerialize()

jsonSerialize() : mixed

Specify data which should be serialized to JSON. This method returns data that can be serialized by json_encode() natively.

Returns

mixed —

assertValidValueReturningKey()

assertValidValueReturningKey(mixed  $value) : string

Asserts valid enum value

Parameters

mixed $value

Returns

string —