Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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);
```