Skip to content

[docs] add final to example classes and add note about from() static method #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use MyCLabs\Enum\Enum;
/**
* Action enum
*/
class Action extends Enum
final class Action extends Enum
{
private const VIEW = 'view';
private const EDIT = 'edit';
Expand All @@ -50,6 +50,8 @@ $action = Action::VIEW();
// or with a dynamic key:
$action = Action::$key();
// or with a dynamic value:
$action = Action::from($value);
// or
$action = new Action($value);
```

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

Static methods:

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

### Static methods

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

```php
class Action extends Enum
final class Action extends Enum
{
private const VIEW = 'view';

Expand All @@ -119,7 +123,7 @@ or you can use phpdoc (this is supported in PhpStorm for example):
* @method static Action VIEW()
* @method static Action EDIT()
*/
class Action extends Enum
final class Action extends Enum
{
private const VIEW = 'view';
private const EDIT = 'edit';
Expand Down