2017 © Pedro Peláez
 

yii2-extension yii2-enum

Enumerable Helper

image

abhi1693/yii2-enum

Enumerable Helper

  • Monday, February 23, 2015
  • by abhi1693
  • Repository
  • 2 Watchers
  • 3 Stars
  • 1,266 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

Yii2-Enum

Dependency Status Code Climate Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Documentation

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist abhi1693/yii2-enum "1.0.0"

or add, (*4)

"abhi1693/yii2-enum": "1.0.0"

to the require section of your composer.json file., (*5)

Usage

The BaseEnum class provides support for enumerated types. The class also provides functionality that may be useful in the course of creating and validation enums. To make use of it, you simply create your own class that extends BaseEnum:, (*6)

use abhimanyu\enum\helpers;

class Month extends BaseEnum
{
    const January = 1;
    const February = 2;
    const March = 3;
    const April = 4;
    const May = 5;
    const June = 6;
    const July = 7;
    const August = 8;
    const September = 9;
    const October = 10;
    const November = 11;
    const December = 12;
}

There are multiple ways to create a new value for an enumerated type:, (*7)

// static call
$month = Month::May();

// direct instantiation
$month = new Month(Month::May);

// by value
$month = Month::createByValue(5);

// by name
$month = Month::createByName('May');

It is possible to retrieve the name and value of the instance of the enumerated type:, (*8)

$name = $month->getName();
$value = $month->getValue();

NOTE: If you have multiple class constants defined with the same value, then an array of names will be returned instead of a string for only one. It will be up to you to decide which to use., (*9)

The class also provides ways of validating names and values:, (*10)

if (Month::isValidName('May')) {
    // it is valid
}

if (Month::isValidValue($value)) {
    // it is valid
}

If you need to retrieve a complete list of possible enum values, you can get them either by name or value:, (*11)

$constantsByName = Month::getConstantsByName();

echo $constantsByName['May']; // 5

$constantsByValue = Month::getConstantsByValue();

echo $constantsByValue[5]; // "May"

How to contribute?

Contributing instructions are located in CONTRIBUTING.md file., (*12)

License

Yii2-Enum is released under the MIT License. See the bundled LICENSE for details., (*13)

The Versions

23/02 2015

dev-master

9999999-dev

Enumerable Helper

  Sources   Download

MIT License

The Requires

 

extension yii2 module enum

29/01 2015

v1.0.0

1.0.0.0

Enumerable Helper

  Sources   Download

MIT License

The Requires

 

extension yii2 module enum