Skip to content

Commit

Permalink
enum
Browse files Browse the repository at this point in the history
  • Loading branch information
teodoroleckie committed Apr 28, 2021
1 parent cbf2154 commit 1b9b70d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions README.md
Expand Up @@ -18,7 +18,7 @@ composer require tleckie/enum

### Usage

Extends class.
Extends Enum class.

```php
<?php
Expand All @@ -38,18 +38,25 @@ class MyEnum extends Enum {

$enum = new MyEnum(3);

// Dynamic static methods available
$enum::VALUE3(); // new MyEnum(3)

$enum::VALUE1(); // new MyEnum(1)

$enum::VALUE2(); // new MyEnum(2)

```
```php
$enum->getValue(); // int(3)

```
```php
$enum->getValue(); // int(3)

```
```php
$enum->getKey(); // "VALUE3"
```

### getValues();
```php
$enum->getValues();
```
Output:
```bash
array(3) {
Expand All @@ -62,8 +69,8 @@ array(3) {
}
```

###getKeys()
```php
// getKeys
$enum->getKeys();
```
Output:
Expand All @@ -77,8 +84,8 @@ array(3) {
string(6) "VALUE3"
}
```
###toArray();
```php
// toArray
$enum->toArray();
```
Output:
Expand All @@ -92,14 +99,10 @@ array(3) {
int(3)
}
```

### Cast string
```php
// string cast
(string) MyEnum::VALUE1(); // "1"
(string) new MyEnum(3); // "3"
(string) new MyEnum( MyEnum::VALUE1() ); // "1"
```

```php
// string cast
(string)MyEnum::VALUE1(); // "1"
```

0 comments on commit 1b9b70d

Please sign in to comment.