https://github.com/morilog/php-enum
A Library for easy working with Enums in php programming language
https://github.com/morilog/php-enum
enum morilog php
Last synced: 9 months ago
JSON representation
A Library for easy working with Enums in php programming language
- Host: GitHub
- URL: https://github.com/morilog/php-enum
- Owner: morilog
- License: mit
- Created: 2019-08-14T16:47:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-14T16:53:57.000Z (over 6 years ago)
- Last Synced: 2025-03-08T10:05:18.623Z (9 months ago)
- Topics: enum, morilog, php
- Language: PHP
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
### PHP-ENUM
There is not any `ENUM` in php programming language. BTW every programmer may need to this feature.
In this library i provide the simple and easy way for working with enums.
##### Installation
Run bellow command:
```bash
composer require morilog/php-enum
```
#### Usage
##### Writing new Enums
Create a class that extends the `\Morilog\PhpEnum\Enum` class
> Constants keys must be all UPPER_CASE and separate words by `_` (underscore)
> Constants values can be all scalar values such as `string`, `integer`, `boolean`, etc.
```php
key(); // APPROVED
$status->value(); // 1
$status->isApproved(); // true
$status->isRejected(); // false
```
##### By `camelCase` constant name
```php
key(); // REJECTED
$status->value(); // 2
$status->isApproved(); // false
$status->isRejected(); // true
$other = CommentStatus::somethingElse();
$other->key(); // SOMETHING_ELSE
$other->value(); // 3
$other->isApproved(); // false
$other->isRejected(); // false
$other->isSomethingElse(); // true
```
##### By `fromKey()` method
```php
1, REJECTED => 2, SOMETHING_ELSE => 3]
```
#### Comparison enums
```php
equalsTo($second); // false
$first->equalsTo($third); // true
```