Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
MyCLabs\Enum\Enum Class Reference

Base Enum class. More...

Inheritance diagram for MyCLabs\Enum\Enum:

Public Member Functions

 __construct ($value)
 Creates a new value of some type.
 
 __toString ()
 @psalm-pure @psalm-suppress InvalidCast
 
 __wakeup ()
 This method exists only for the compatibility reason when deserializing a previously serialized version that didn't had the key property.
 
 equals ($variable=null)
 Determines if Enum should be considered equal with the variable passed as a parameter.
 
 getKey ()
 Returns the enum key (i.e.
 
 getValue ()
 @psalm-pure
 
 jsonSerialize ()
 Specify data which should be serialized to JSON.
 

Static Public Member Functions

static __callStatic ($name, $arguments)
 Returns a value when called statically like so: MyEnum\SOME_VALUE() given SOME_VALUE is a class constant.
 
static assertValidValue ($value)
 Asserts valid enum value.
 
static from ($value)
 
static isValid ($value)
 Check if is valid enum value.
 
static isValidKey ($key)
 Check if is valid enum key.
 
static keys ()
 Returns the names (keys) of all constants in the Enum class.
 
static search ($value)
 Return key for value.
 
static toArray ()
 Returns all possible values as an array.
 
static values ()
 Returns instances of the Enum class of all Enum constants.
 

Protected Attributes

mixed $value
 Enum value.
 

Static Protected Attributes

static array $cache = []
 Store existing constants in a static cache per object.
 
static array $instances = []
 Cache of instances of the Enum class.
 

Detailed Description

Base Enum class.

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

Author
Matthieu Napoli matth.nosp@m.ieu@.nosp@m.mnapo.nosp@m.li.f.nosp@m.r
Daniel Costa danie.nosp@m.lcos.nosp@m.ta@gm.nosp@m.ail..nosp@m.com
Mirosław Filip mirfi.nosp@m.lip@.nosp@m.gmail.nosp@m..com

@psalm-template T @psalm-immutable @psalm-consistent-constructor

Constructor & Destructor Documentation

◆ __construct()

MyCLabs\Enum\Enum::__construct ( $value)

Creates a new value of some type.

@psalm-pure

Parameters
mixed$value

@psalm-param T $value

Exceptions
UnexpectedValueExceptionif incompatible type is given.

Member Function Documentation

◆ __callStatic()

static MyCLabs\Enum\Enum::__callStatic ( $name,
$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
Return values
static
Exceptions
BadMethodCallException

@psalm-pure

◆ __toString()

MyCLabs\Enum\Enum::__toString ( )

@psalm-pure @psalm-suppress InvalidCast

Return values
string

◆ assertValidValue()

static MyCLabs\Enum\Enum::assertValidValue ( $value)
static

Asserts valid enum value.

@psalm-pure @psalm-assert T $value

Parameters
mixed$value

◆ equals()

MyCLabs\Enum\Enum::equals ( $variable = null)
final

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

@psalm-pure @psalm-param mixed $variable

Return values
bool

◆ from()

static MyCLabs\Enum\Enum::from ( $value)
static
Parameters
mixed$value
Return values
static

◆ getKey()

MyCLabs\Enum\Enum::getKey ( )

Returns the enum key (i.e.

the constant name).

@psalm-pure

Return values
string

◆ getValue()

MyCLabs\Enum\Enum::getValue ( )

@psalm-pure

Return values
mixed@psalm-return T

◆ isValid()

static MyCLabs\Enum\Enum::isValid ( $value)
static

Check if is valid enum value.

Parameters
$value@psalm-param mixed $value @psalm-pure @psalm-assert-if-true T $value
Return values
bool

◆ isValidKey()

static MyCLabs\Enum\Enum::isValidKey ( $key)
static

Check if is valid enum key.

Parameters
$key@psalm-param string $key @psalm-pure
Return values
bool

◆ jsonSerialize()

MyCLabs\Enum\Enum::jsonSerialize ( )

Specify data which should be serialized to JSON.

This method returns data that can be serialized by json_encode() natively.

Return values
mixed@externalurl http://php.net/manual/en/jsonserializable.jsonserialize.php @psalm-pure

◆ keys()

static MyCLabs\Enum\Enum::keys ( )
static

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

@psalm-pure @psalm-return list<string>

Return values
array

◆ search()

static MyCLabs\Enum\Enum::search ( $value)
static

Return key for value.

Parameters
mixed$value

@psalm-param mixed $value @psalm-pure

Return values
string|false

◆ toArray()

static MyCLabs\Enum\Enum::toArray ( )
static

Returns all possible values as an array.

@psalm-pure @psalm-suppress ImpureStaticProperty

@psalm-return array<string, mixed>

Return values
arrayConstant name in key, constant value in value

◆ values()

static MyCLabs\Enum\Enum::values ( )
static

Returns instances of the Enum class of all Enum constants.

@psalm-pure @psalm-return array<string, static>

Return values
static[]Constant name in key, Enum instance in value

Member Data Documentation

◆ $cache

array MyCLabs\Enum\Enum::$cache = []
staticprotected

Store existing constants in a static cache per object.

@psalm-var array<class-string, array<string, mixed>>

◆ $instances

array MyCLabs\Enum\Enum::$instances = []
staticprotected

Cache of instances of the Enum class.

@psalm-var array<class-string, array<string, static>>

◆ $value

mixed MyCLabs\Enum\Enum::$value
protected

Enum value.

@psalm-var T


The documentation for this class was generated from the following file: