https://github.com/manchenkoff/php-enum
Enumeration type - PHP implementation with useful magic methods
https://github.com/manchenkoff/php-enum
enum enumeration laravel oop php php-library php7 yii2
Last synced: 4 months ago
JSON representation
Enumeration type - PHP implementation with useful magic methods
- Host: GitHub
- URL: https://github.com/manchenkoff/php-enum
- Owner: manchenkoff
- Archived: true
- Created: 2020-05-24T23:19:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-07T22:20:53.000Z (over 5 years ago)
- Last Synced: 2025-08-01T16:11:26.599Z (9 months ago)
- Topics: enum, enumeration, laravel, oop, php, php-library, php7, yii2
- Language: PHP
- Homepage: https://packagist.org/packages/manchenkov/php-enum
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# PHP Enum
Basic enumeration implementation in PHP, easy and ready to use.
- *Enum*: to create simple enumeration class
- *StrictEnum*: to create enumeration with strict variables type
## Installation
You have to run following command to add a dependency to your project
```bash
composer require manchenkov/php-enum
```
or you can add this line to `require` section of `composer.json`
```
"manchenkov/php-enum": "*"
```
## How to use
Create a new class like `UserType.php` and paste the following code example:
```php
use Manchenkov\Enumeration\Enum;
/**
* @method static UserType MANAGER()
* @method static UserType ADMIN()
*/
class UserType extends Enum
{
/**
* @title Manager role description
*/
private const MANAGER = 'user_manager';
/**
* @title Administrator role description
*/
private const ADMIN = 'user_admin';
}
```
Now You can create a new instance of `UserType` enumeration and work with some methods:
```php
$manager = UserType::MANAGER();
$manager->getName(); // MANAGER
$manager->getValue(); // user_manager
$manager->getTitle(); // Manager role description
$manager->is(UserType::ADMIN()); // false
$manager->eq('user_manager'); // true
```