https://github.com/artkonekt/enum
PHP Enum Component
https://github.com/artkonekt/enum
enum php-enum
Last synced: 7 months ago
JSON representation
PHP Enum Component
- Host: GitHub
- URL: https://github.com/artkonekt/enum
- Owner: artkonekt
- License: mit
- Created: 2016-05-30T20:15:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-03T12:26:02.000Z (11 months ago)
- Last Synced: 2025-05-19T12:07:56.203Z (8 months ago)
- Topics: enum, php-enum
- Language: PHP
- Size: 126 KB
- Stars: 20
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Konekt Enum
[](https://github.com/artkonekt/enum/actions?query=workflow%3Atests)
[](https://packagist.org/packages/konekt/enum)
[](https://packagist.org/packages/konekt/enum)
[](https://styleci.io/repos/60036504)
[](LICENSE.md)
## PHP Enum Class
> Enums are handy when a variable (especially a method parameter) can only take one out of a small set of possible values.
Konekt Enum is a lightweight abstract class that enables creation of PHP enums.
> **Why not PHP 8.1 Enums?** This package was created back in 2013, and has been in use across many libraries.
> We're planning to find the way to make this package be based on native PHP enums AND keep compatibility
> with earlier versions as much as possible. This is expected in the **v5.0** release of this package.
### Usage
Extend the base class and define constants on it:
##### Example
```php
class ChessPiece extends \Konekt\Enum\Enum {
const KING = 'king';
const QUEEN = 'queen';
const ROOK = 'rook';
const BISHOP = 'bishop';
const KNIGHT = 'knight';
const PAWN = 'pawn';
}
var $queen = new ChessPiece('queen');
```
## Installation
using composer: `composer require konekt/enum`
## Documentation
For detailed usage and examples go to the
[Konekt Enum Documentation](https://konekt.dev/enum) or refer to the
markdown files in the `docs/` folder of this repo.
For the list of changes read the [Changelog](Changelog.md).
## Upgrade
- From 3.x -> 4.x see [Upgrade to 4.0](https://konekt.dev/enum/4.x/upgrade#from-v3-to-v4)
- From 2.x -> 3.x see [Upgrade to 3.0](https://konekt.dev/enum/4.x/upgrade#from-v2-to-v3)
- From 1.x -> 2.x see [Upgrade to 2.0](https://konekt.dev/enum/4.x/upgrade#from-v1-to-v2)
## Laravel Eloquent Integration
There is a tiny trait for Laravel that helps you to automatically map fields of Eloquent models to/from Enum objects. For more details go to the [konekt/enum-eloquent](https://github.com/artkonekt/enum-eloquent) package.