Skip to content

granam/integer-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enumeration with integers

Usage

  1. Use enum
  2. NULL is NULL, not Enum
  3. Installation

Use enum

<?php
use \Granam\IntegerEnum\IntegerEnum;

$enum = IntegerEnum::getEnum(12345);
echo $enum->getValue(); // 12345
var_dump($enum->is('12345')); // false
var_dump($enum->is(12345)); // true
var_dump($enum->is($enum)); // true
var_dump($enum->is(IntegerEnum::getEnum(12345))); // true
var_dump($enum->is(IntegerEnum::getEnum(99999))); // false

NULL is NULL, enum can not hold it

You can not create IntegerEnum with NULL value. Just use NULL directly for such value.

<?php
try {
    \Granam\IntegerEnum\IntegerEnum::getEnum(null);
} catch(\Granam\IntegerEnum\Exceptions\UnexpectedValueToConvert $unexpectedValueToEnum) {
    echo $unexpectedValueToEnum->getMessage(); // Expected scalar or object with __toString method on strict mode, got NULL
}

Installation

composer.phar require granam/integer-enum

or manually edit composer.json at your project and "require": block (extend existing)

"require": {
    "granam/integer-enum": "dev-master"
}

About

Enumeration with integers only

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages