feat(doc): add Enum::entries() to README

This commit is contained in:
Victor Westerlund 2023-10-09 13:31:53 +02:00 committed by GitHub
parent 5a686958fe
commit 0f6ac61877
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,28 @@ HelloWorld::fromName("FOO"); // HelloWorld::FOO
HelloWorld::tryFromName("MOM"); // null HelloWorld::tryFromName("MOM"); // null
``` ```
# How to use
Requires PHP 8.0 or newer
1. **Install from composer**
```
composer require victorwesterlund/xenum
```
2. **`use` in your project**
```php
use \victorwesterlund\xEnum;
```
3. **`use` with your Enums**
```php
enum HelloWorld {
use xEnum;
}
```
# Methods # Methods
All methods implemented by this library All methods implemented by this library
@ -32,6 +54,7 @@ Method
[Enum::tryFromName(int\|string\|null): static\|null](#enumtryfromname) [Enum::tryFromName(int\|string\|null): static\|null](#enumtryfromname)
[Enum::names(): array](#enumnames) [Enum::names(): array](#enumnames)
[Enum::values(): array](#enumvalues) [Enum::values(): array](#enumvalues)
[Enum::entries(): array](#enumentries)
## Enum::fromName() ## Enum::fromName()
@ -107,7 +130,7 @@ HelloWorld::names(); // ["FOO", "BAZ"]
Return sequential array of Enum case values Return sequential array of Enum case values
```php ```php
Enum::values(): array Enum::entries(): array
``` ```
Example: Example:
@ -123,23 +146,23 @@ enum HelloWorld: string {
HelloWorld::values(); // ["BAR", "QUX"] HelloWorld::values(); // ["BAR", "QUX"]
``` ```
# How to use ## Enum::entries()
Requires PHP 8.0 or newer Return an associative array of Enum names and values. This method is similar to [JavaScript's Object.entries()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
1. **Install from composer**
```
composer require victorwesterlund/xenum
```
2. **`use` in your project**
```php ```php
use \victorwesterlund\xEnum; Enum::entries(): array
``` ```
3. **`use` with your Enums** Example:
```php ```php
enum HelloWorld { enum HelloWorld: string {
use xEnum; use xEnum;
case FOO = "BAR";
case BAZ = "QUX";
} }
HelloWorld::entries(); // ["FOO" => "BAR", "BAZ" => "QUX"]
``` ```