2017 © Pedro Peláez
 

library enum

A simple ENUM object for PHP

image

simondeeley/enum

A simple ENUM object for PHP

  • Monday, December 4, 2017
  • by unwarysheep
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

ENUM object for PHP

License Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality Code Coverage, (*1)

A simple library for adding ENUM type objects into any existing or new PHP project., (*2)

Requirements

  • PHP >= 7.1

Installation

composer require simondeeley/enum

Usage

Create a new Enum class using your own chosen enum types, (*3)

use simondeeley\enum;

class MyAwesomeEnum extends Enum
{
    const FOO = 'FOO';
    const BAR = 'BAR';
}

Now you can use your newly designed enum object in your code. Just simply instantiate a new MyAwesomeEnum every time you want to use an enum. The constants you defined in the class definition determine what the allowed values of the enum object can take. You can add as many constants as you wish, depending on your design needs., (*4)

Every time a new instance of your enum object is created, it requires that you pass a value to it's constructor. If the value passed to the constructor is not one of the pre-determined values then an InvalidArgumentException will be thrown., (*5)

use Acme\MyAwesomeEnum;

$good = new MyAwesomeEnum('FOO');
$bad = new MyAwesomeEnum('BAZ'); // throws an exception

Examples

This package provides two enums for out-of-the-box use, Boolean and Weekday. The first, Boolean leverages an enum that is either true or false whilst the second is a list of the days of the week., (*6)

use simondeeley\Enums\Boolean;
use simondeeley\Enums\Weekday;

$true = new Boolean('TRUE');
$true->getValue(); // returns (bool) true

$tuesday = new Weekday('TUESDAY');
$tuesday->getValue(); // returns (string) "Tuesday"

Although not mandatory when building enum objects, both Boolean and Weekday each provide short-cut static methods to quickly create a new object, for example:, (*7)

$true = Boolean::true();

$saturday = Weekday::Saturday();

This functionality is built-in to any enums extending the base Enum type object. The only caveats are that when performing static method calls that it is best to keep in-line with PHP good coding practice and to ensure all constants are typed in uppercase., (*8)

The Versions

04/12 2017

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

php enum immutable

04/12 2017

v1.1.2

1.1.2.0 https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

php enum immutable

04/12 2017

dev-master

9999999-dev https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

php enum immutable

30/11 2017

v1.1.1

1.1.1.0 https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

php enum immutable

30/11 2017

v1.1.0

1.1.0.0 https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

php enum immutable

25/11 2017

v1.0

1.0.0.0 https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

php enum immutable

25/11 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/simondeeley

A simple ENUM object for PHP

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

php enum immutable