yii2-enumerables

Usage

EnumBoolean

Generates a boolean array. You can pass the false label (default No) and true label (default Yes).

<?php
use wbraganca\enumerables\EnumBoolean;

print_r(EnumBoolean::getConstList());
print_r(EnumBoolean::getConstList('Inactive', 'Active'));

/** OUTPUT
Array
(
    [0] => No
    [1] => Yes
)
Array
(
    [0] => Inactive
    [1] => Active
) */

EnumYear

Generates an array of years between from and to years. Years till current system date will be generated if to year is not specified.

<?php
use wbraganca\enumerables\EnumYear;

print_r(EnumYear::getConstList(2015, 2012));
print_r(EnumYear::getConstList(2012, 2015));

/** OUTPUT
Array
(
    [2015] => 2015
    [2014] => 2014
    [2013] => 2013
    [2012] => 2012
)
Array
(
    [2012] => 2012
    [2013] => 2013
    [2014] => 2014
    [2015] => 2015
) */

EnumMonth

Generates an array of months.

<?php
use wbraganca\enumerables\EnumMonth;

EnumMonth::getLabel(EnumMonth::JANUARY); //OUTPUT: "January"
EnumMonth::getLabel(1, ['abbr' => true, 'case' => 'upper']); // OUTPUT: "JAN"
EnumMonth::getLabel(1, ['case' => 'lower']); // OUTPUT: "january"

print_r(EnumMonth::getConstList());
print_r(EnumMonth::getConstList(['abbr' => true, 'case' => 'upper']));

/** OUTPUT
Array
(
    [1] => January
    [2] => February
    [3] => March
    [4] => April
    [5] => May
    [6] => June
    [7] => July
    [8] => August
    [9] => September
    [10] => October
    [11] => November
    [12] => December
)
Array
(
    [1] => JAN
    [2] => FEB
    [3] => MAR
    [4] => APR
    [5] => MAY
    [6] => JUN
    [7] => JUL
    [8] => AUG
    [9] => SEP
    [10] => OCT
    [11] => NOV
    [12] => DEC
) */

EnumDay

Generates an array of days.

<?php
use wbraganca\enumerables\EnumDay;

EnumDay::getLabel(EnumDay::MONDAY); // OUTPUT: "Monday"
EnumDay::getLabel(7, ['abbr' => true, 'case' => 'upper']); // OUTPUT: "SAT"
EnumDay::getLabel(7, ['abbr' => true, 'case' => 'lower']); // OUTPUT:"sat"

print_r(EnumDay::getConstList());
print_r(EnumDay::getConstList(['abbr' => true, 'case' => 'upper']));

/** OUTPUT
Array
(
    [1] => Sunday
    [2] => Monday
    [3] => Tuesday
    [4] => Wednesday
    [5] => Thursday
    [6] => Friday
    [7] => Saturday
)
Array
(
    [1] => SUN
    [2] => MON
    [3] => TUE
    [4] => WED
    [5] => THU
    [6] => FRI
    [7] => SAT
) */