Base Enum class.
More...
|
| | __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 | __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.
|
| |
|
| static array | $cache = [] |
| | Store existing constants in a static cache per object.
|
| |
| static array | $instances = [] |
| | Cache of instances of the Enum class.
|
| |
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
◆ __construct()
| MyCLabs\Enum\Enum::__construct |
( |
| $value | ) |
|
Creates a new value of some type.
@psalm-pure
- Parameters
-
@psalm-param T $value
- Exceptions
-
| UnexpectedValueException | if incompatible type is given. |
◆ __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
-
- Exceptions
-
@psalm-pure
◆ __toString()
| MyCLabs\Enum\Enum::__toString |
( |
| ) |
|
@psalm-pure @psalm-suppress InvalidCast
- Return values
-
◆ assertValidValue()
| static MyCLabs\Enum\Enum::assertValidValue |
( |
| $value | ) |
|
|
static |
Asserts valid enum value.
@psalm-pure @psalm-assert T $value
- Parameters
-
◆ 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
-
◆ from()
| static MyCLabs\Enum\Enum::from |
( |
| $value | ) |
|
|
static |
◆ getKey()
| MyCLabs\Enum\Enum::getKey |
( |
| ) |
|
Returns the enum key (i.e.
the constant name).
@psalm-pure
- Return values
-
◆ getValue()
| MyCLabs\Enum\Enum::getValue |
( |
| ) |
|
@psalm-pure
- Return values
-
◆ 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
-
◆ isValidKey()
| static MyCLabs\Enum\Enum::isValidKey |
( |
| $key | ) |
|
|
static |
Check if is valid enum key.
- Parameters
-
| $key | @psalm-param string $key @psalm-pure |
- Return values
-
◆ 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
-
◆ 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
-
◆ search()
| static MyCLabs\Enum\Enum::search |
( |
| $value | ) |
|
|
static |
Return key for value.
- Parameters
-
@psalm-param mixed $value @psalm-pure
- Return values
-
◆ 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
-
| array | Constant 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 |
◆ $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 |
The documentation for this class was generated from the following file:
- lib/php-enum/src/Enum.php