Skip to content

Commit 1fbdbfb

Browse files
committed
document names() options() values()
1 parent e651310 commit 1fbdbfb

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

README.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Enums
22

3-
A collection\* of enum helpers for PHP.
3+
A collection of enum helpers for PHP.
44

5-
\* Currently there's only one helper — [`InvokableCases`](#invokablecases) — but the goal of the package is to provide general purpose enum helpers.
5+
- [`InvokableCases`](#invokablecases)
6+
- [`Names`](#names)
7+
- [`Values`](#values)
8+
- [`Options`](#options)
69

7-
You can read more about the idea on [Twitter](https://twitter.com/archtechx/status/1495158228757270528). I originally wanted to include that helper in [`archtechx/helpers`](https://github.com/archtechx/helpers), but it makes more sense to make it a separate dependency and use it *inside* the other package.
10+
You can read more about the idea on [Twitter](https://twitter.com/archtechx/status/1495158228757270528). I originally wanted to include the helper in [`archtechx/helpers`](https://github.com/archtechx/helpers), but it makes more sense to make it a separate dependency and use it *inside* the other package.
811

912
## Installation
1013

@@ -72,6 +75,75 @@ public function updateStatus(TaskStatus $status)
7275
}
7376
```
7477

78+
### Names
79+
80+
This helper returns a list of case *names* in the enum.
81+
82+
#### Apply the trait on your enum
83+
```php
84+
use ArchTech\Enums\Names;
85+
86+
enum TaskStatus: int
87+
{
88+
use Names;
89+
90+
case INCOMPLETE = 0;
91+
case COMPLETED = 1;
92+
case CANCELED = 2;
93+
}
94+
```
95+
96+
#### Use the `names()` method
97+
```php
98+
TaskStatus::names(); // ['INCOMPLETE', 'COMPLETED', 'CANCELED']
99+
```
100+
101+
### Values
102+
103+
This helper returns a list of case *values* in the enum.
104+
105+
#### Apply the trait on your enum
106+
```php
107+
use ArchTech\Enums\Values;
108+
109+
enum TaskStatus: int
110+
{
111+
use Values;
112+
113+
case INCOMPLETE = 0;
114+
case COMPLETED = 1;
115+
case CANCELED = 2;
116+
}
117+
```
118+
119+
#### Use the `values()` method
120+
```php
121+
TaskStatus::values(); // [0, 1, 2]
122+
```
123+
124+
### Options
125+
126+
This helper returns an associative array of case names and values.
127+
128+
#### Apply the trait on your enum
129+
```php
130+
use ArchTech\Enums\Options;
131+
132+
enum TaskStatus: int
133+
{
134+
use Options;
135+
136+
case INCOMPLETE = 0;
137+
case COMPLETED = 1;
138+
case CANCELED = 2;
139+
}
140+
```
141+
142+
#### Use the `options()` method
143+
```php
144+
TaskStatus::options(); // ['INCOMPLETE' => 0, 'COMPLETED' => 1, 'CANCELED' => 2]
145+
```
146+
75147
## Development
76148

77149
Run all checks locally:

0 commit comments

Comments
 (0)