Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Syntax Highlighting Great Again #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 41 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,66 @@ also forces enums to be singletons.
Installation
------------

composer require tebru/enum
```bash
composer require tebru/enum
```

Usage
-----

To use, extend `AbstractEnum` and implement the getConstants() method.

class DirectionEnum extends AbstractEnum
```php
class DirectionEnum extends AbstractEnum
{
const NORTH = 'north';
const EAST = 'east';
const SOUTH = 'south';
const WEST = 'west';

/**
* Return an array of enum class constants
*
* @return array
*/
public static function getConstants()
{
const NORTH = 'north';
const EAST = 'east';
const SOUTH = 'south';
const WEST = 'west';

/**
* Return an array of enum class constants
*
* @return array
*/
public static function getConstants()
{
return [
self::NORTH,
self::EAST,
self::SOUTH,
self::WEST,
];
}
return [
self::NORTH,
self::EAST,
self::SOUTH,
self::WEST,
];
}
}
```

Now you can create a new instance using the static method.

DirectionEnum::create('north');
```php
DirectionEnum::create('north');
```

You can also create an instance using the __callStatic magic method.

DirectionEnum::NORTH();

```php
DirectionEnum::NORTH();
```

Add a hint to the enum doc block

/**
* @method static $this NORTH()
*/
```php
/**
* @method static $this NORTH()
*/
```

You can also iterate over the enum

$enum = new DirectionEnum('north');
foreach ($enum as $key => $value) {}
```php
$enum = new DirectionEnum('north');
foreach ($enum as $key => $value) {}
```

Reference
---------
Expand Down