You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Extend functionality to work with pure enums
* Code review changes
Altered `::values()` to act like `::names()` for backed enums, code style fixes, general cleanups
This helper lets you get the value of a backed enum by "invoking" it — either statically (`MyEnum::FOO()` instead of `MyEnum::FOO`), or as an instance (`$enum()`).
24
+
This helper lets you get the value of a backed enum, or the name of a pure enum, by "invoking" it — either statically (`MyEnum::FOO()` instead of `MyEnum::FOO`), or as an instance (`$enum()`).
25
25
26
26
That way, you can use enums as array keys:
27
27
```php
@@ -58,20 +58,32 @@ enum TaskStatus: int
58
58
case COMPLETED = 1;
59
59
case CANCELED = 2;
60
60
}
61
+
62
+
enum Role
63
+
{
64
+
use InvokableCases;
65
+
66
+
case ADMINISTRATOR;
67
+
case SUBSCRIBER;
68
+
case GUEST;
69
+
}
61
70
```
62
71
63
72
#### Use static calls to get the primitive value
64
73
```php
65
74
TaskStatus::INCOMPLETE(); // 0
66
75
TaskStatus::COMPLETED(); // 1
67
76
TaskStatus::CANCELED(); // 2
77
+
Role::ADMINISTRATOR(); // 'ADMINISTRATOR'
78
+
Role::SUBSCRIBER(); // 'SUBSCRIBER'
79
+
Role::GUEST(); // 'GUEST'
68
80
```
69
81
70
82
#### Invoke instances to get the primitive value
71
83
```php
72
-
public function updateStatus(TaskStatus $status)
84
+
public function updateStatus(TaskStatus $status, Role $role)
This helper returns a list of case *values*in the enum.
125
+
This helper returns a list of case *values*for backed enums, or a list of case *names* for pure enums (making this functionally equivalent to [`::names()`](#names) for pure Enums)
This helper returns an associative array of case names and values.
158
+
This helper returns an associative array of case names and values for backed enums, or a list of names for pure enums (making this functionally equivalent to [`::names()`](#names) for pure Enums).
0 commit comments