-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
212 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Value | ||
|
||
When you have a unit enum, you have no value. You have to use the `name` value. But what if you | ||
want to have the lowercase version of that name? That's where `Value` comes in. | ||
|
||
## Usage | ||
|
||
```php | ||
use Henzeb\Enumhancer\Concerns\Value; | ||
|
||
enum yourEnum { | ||
use Value; | ||
|
||
case MY_ENUM; | ||
|
||
} | ||
``` | ||
|
||
### Examples | ||
|
||
```php | ||
YourEnum::MY_ENUM->value(); // will return `my_enum`; | ||
``` | ||
|
||
Note: When used with a string or int backed enum, this method will return it's actual value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\Concerns; | ||
|
||
trait Value | ||
{ | ||
public function value(): string|int | ||
{ | ||
return $this->value ?? strtolower($this->name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\Tests\Fixtures; | ||
|
||
use Henzeb\Enumhancer\Concerns\Constructor; | ||
use Henzeb\Enumhancer\Concerns\Enhancers; | ||
use Henzeb\Enumhancer\Contracts\Mapper; | ||
|
||
/** | ||
* @method static self anotherMappedEnum() | ||
*/ | ||
enum EnhancedUnitEnum | ||
{ | ||
use Enhancers, Constructor; | ||
|
||
case ENUM; | ||
case ANOTHER_ENUM; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.