Skip to content

Commit be0c9d5

Browse files
authored
Merge pull request #139 from drealecs/patch-1
[docs] add final to example classes and add note about from() static method
2 parents ea06934 + b50f4ad commit be0c9d5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use MyCLabs\Enum\Enum;
3535
/**
3636
* Action enum
3737
*/
38-
class Action extends Enum
38+
final class Action extends Enum
3939
{
4040
private const VIEW = 'view';
4141
private const EDIT = 'edit';
@@ -50,6 +50,8 @@ $action = Action::VIEW();
5050
// or with a dynamic key:
5151
$action = Action::$key();
5252
// or with a dynamic value:
53+
$action = Action::from($value);
54+
// or
5355
$action = new Action($value);
5456
```
5557

@@ -73,17 +75,19 @@ function setAction(Action $action) {
7375

7476
Static methods:
7577

78+
- `from()` Creates an Enum instance, checking that the value exist in the enum
7679
- `toArray()` method Returns all possible values as an array (constant name in key, constant value in value)
7780
- `keys()` Returns the names (keys) of all constants in the Enum class
7881
- `values()` Returns instances of the Enum class of all Enum constants (constant name in key, Enum instance in value)
7982
- `isValid()` Check if tested value is valid on enum set
8083
- `isValidKey()` Check if tested key is valid on enum set
84+
- `assertValidValue()` Assert the value is valid on enum set, throwing exception otherwise
8185
- `search()` Return key for searched value
8286

8387
### Static methods
8488

8589
```php
86-
class Action extends Enum
90+
final class Action extends Enum
8791
{
8892
private const VIEW = 'view';
8993
private const EDIT = 'edit';
@@ -99,7 +103,7 @@ Static method helpers are implemented using [`__callStatic()`](http://www.php.ne
99103
If you care about IDE autocompletion, you can either implement the static methods yourself:
100104

101105
```php
102-
class Action extends Enum
106+
final class Action extends Enum
103107
{
104108
private const VIEW = 'view';
105109

@@ -119,7 +123,7 @@ or you can use phpdoc (this is supported in PhpStorm for example):
119123
* @method static Action VIEW()
120124
* @method static Action EDIT()
121125
*/
122-
class Action extends Enum
126+
final class Action extends Enum
123127
{
124128
private const VIEW = 'view';
125129
private const EDIT = 'edit';

0 commit comments

Comments
 (0)