Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 400 and 403] [Versions 401 and 403]

(no description)

License: http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
File Size: 318 lines (8 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Enum:: (17 methods):
  __construct()
  __wakeup()
  from()
  getValue()
  getKey()
  __toString()
  equals()
  keys()
  values()
  toArray()
  isValid()
  assertValidValue()
  assertValidValueReturningKey()
  isValidKey()
  search()
  __callStatic()
  jsonSerialize()


Class: Enum  - X-Ref

Base Enum class

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

__construct($value)   X-Ref
Creates a new value of some type

param: mixed $value

__wakeup()   X-Ref
This method exists only for the compatibility reason when deserializing a previously serialized version
that didn't had the key property


from($value)   X-Ref

param: mixed $value
return: static

getValue()   X-Ref

return: mixed

getKey()   X-Ref
Returns the enum key (i.e. the constant name).

return: string

__toString()   X-Ref

return: string

equals($variable = null)   X-Ref
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

return: bool

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

return: array

values()   X-Ref
Returns instances of the Enum class of all Enum constants

return: static[] Constant name in key, Enum instance in value

toArray()   X-Ref
Returns all possible values as an array

return: array Constant name in key, constant value in value

isValid($value)   X-Ref
Check if is valid enum value

param: $value
return: bool

assertValidValue($value)   X-Ref
Asserts valid enum value

param: mixed $value

assertValidValueReturningKey($value)   X-Ref
Asserts valid enum value

param: mixed $value
return: string

isValidKey($key)   X-Ref
Check if is valid enum key

param: $key
return: bool

search($value)   X-Ref
Return key for value

param: mixed $value
return: string|false

__callStatic($name, $arguments)   X-Ref
Returns a value when called statically like so: MyEnum::SOME_VALUE() given SOME_VALUE is a class constant

param: string $name
param: array  $arguments
return: static

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

return: mixed