Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hakobyansen/phpenum
All constants in your class, which extends Enum, will be converted to array of enum options.
https://github.com/hakobyansen/phpenum
constants enum php reflection-api
Last synced: about 1 month ago
JSON representation
All constants in your class, which extends Enum, will be converted to array of enum options.
- Host: GitHub
- URL: https://github.com/hakobyansen/phpenum
- Owner: hakobyansen
- Created: 2021-05-02T18:40:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T11:09:55.000Z (over 3 years ago)
- Last Synced: 2024-10-13T23:00:12.607Z (3 months ago)
- Topics: constants, enum, php, reflection-api
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP Enum
> This package provides you a class named Enum. It is designed to help you to structure
> your Enum classes easily and get rid of the most boilerplate code.## Usage
### Installation
Install via composer:
```
composer require codebot/phpenum
```### How to use
All your Enum classes should extend the abstract `Enum` class.
All constants in your class, which extends `Enum`, will be converted to enum options.```php
toArray(); // will return [ 'active' => 'active', 'inactive' => 'inactive', 'blocked' => 'blocked' ]
$status->hasValue('active'); // will return boolean
$status->hasKey('blocked'); // will return boolean
```Enum constructor has 2 parameters: `$caseLower=true` and `$caseUpper=false`.
If you want the case of array keys to be same as constants case - pass `false` as `$caseLower`.
```php
$status = new Status(false);
```If you want the case of array keys to be uppercase - pass `false` as `$caseLower` and `true` as `$caseUpper`.
```php
$status = new Status(false, true);
```