@@ -35,7 +35,7 @@ use MyCLabs\Enum\Enum;
35
35
/**
36
36
* Action enum
37
37
*/
38
- class Action extends Enum
38
+ final class Action extends Enum
39
39
{
40
40
private const VIEW = 'view';
41
41
private const EDIT = 'edit';
@@ -50,6 +50,8 @@ $action = Action::VIEW();
50
50
// or with a dynamic key:
51
51
$action = Action::$key();
52
52
// or with a dynamic value:
53
+ $action = Action::from($value);
54
+ // or
53
55
$action = new Action($value);
54
56
```
55
57
@@ -73,17 +75,19 @@ function setAction(Action $action) {
73
75
74
76
Static methods:
75
77
78
+ - ` from() ` Creates an Enum instance, checking that the value exist in the enum
76
79
- ` toArray() ` method Returns all possible values as an array (constant name in key, constant value in value)
77
80
- ` keys() ` Returns the names (keys) of all constants in the Enum class
78
81
- ` values() ` Returns instances of the Enum class of all Enum constants (constant name in key, Enum instance in value)
79
82
- ` isValid() ` Check if tested value is valid on enum set
80
83
- ` isValidKey() ` Check if tested key is valid on enum set
84
+ - ` assertValidValue() ` Assert the value is valid on enum set, throwing exception otherwise
81
85
- ` search() ` Return key for searched value
82
86
83
87
### Static methods
84
88
85
89
``` php
86
- class Action extends Enum
90
+ final class Action extends Enum
87
91
{
88
92
private const VIEW = 'view';
89
93
private const EDIT = 'edit';
@@ -99,7 +103,7 @@ Static method helpers are implemented using [`__callStatic()`](http://www.php.ne
99
103
If you care about IDE autocompletion, you can either implement the static methods yourself:
100
104
101
105
``` php
102
- class Action extends Enum
106
+ final class Action extends Enum
103
107
{
104
108
private const VIEW = 'view';
105
109
@@ -119,7 +123,7 @@ or you can use phpdoc (this is supported in PhpStorm for example):
119
123
* @method static Action VIEW()
120
124
* @method static Action EDIT()
121
125
*/
122
- class Action extends Enum
126
+ final class Action extends Enum
123
127
{
124
128
private const VIEW = 'view';
125
129
private const EDIT = 'edit';
0 commit comments