Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/werkspot/enum
https://github.com/werkspot/enum
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/werkspot/enum
- Owner: Werkspot
- License: mit
- Created: 2016-03-24T15:11:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-29T08:08:28.000Z (over 4 years ago)
- Last Synced: 2024-10-29T00:21:01.470Z (2 months ago)
- Language: PHP
- Size: 18.6 KB
- Stars: 2
- Watchers: 32
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Enum
This package holds a simple class that may be used as an ancestor for your enum classes.[![Build Status](https://travis-ci.com/Werkspot/Enum.svg?branch=master)](https://travis-ci.com/Werkspot/Enum)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Werkspot/Enum/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Werkspot/Enum/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/Werkspot/Enum/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Werkspot/Enum/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/werkspot/enum/v/stable)](https://packagist.org/packages/werkspot/enum)
[![License](https://poser.pugx.org/werkspot/enum/license)](https://packagist.org/packages/werkspot/enum)### Install
`# composer require werkspot/enum`
### Usage
Extend the Werkspot\Enum\AbstractEnum, define your enum key values as constants.
```php
namespace YourAwesomeOrganisation\Project;use Werkspot\Enum\AbstractEnum;
/**
* @method static FooEnum foo()
* @method bool isFoo()
* @method static FooEnum bar()
* @method bool isBar()
* @method static FooEnum baz()
* @method bool isBaz()
*/
final class FooEnum extends AbstractEnum
{
const FOO = 'foo';
const BAR = 'bar';
const BAZ = 'baz';
}
```Now you can use the enum in a class:
```php
namespace YourAwesomeOrganisation\Project;final class Bar
{
/** @var FooEnum */
private $enum;
punblic function __construct(FooEnum $enum)
{
$this->enum = $enum;
}
public function getEnum(): FooEnum
{
return $this->enum;
}
}
```
Implementation of that class```php
$fooEnum = FooEnum::baz();
$bar = new Bar($fooEnum);$enum = $bar->getEnum();
$value = $enum->getValue(); // will return 'baz'
```