2017 © Pedro Peláez
 

library enum

Enum is a simple implementation of php enumeration type.

image

ngabor84/enum

Enum is a simple implementation of php enumeration type.

  • Tuesday, March 14, 2017
  • by ngabor84
  • Repository
  • 0 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Enum

Codeship Status for ngabor84/enum, (*1)

About

Enum is a simple implementation of php's missing enumeration type., (*2)

Requirements

  • PHP 7.0 or above

Installation

Install Enum via the composer package manager from packagist ngabor84/enum., (*3)

Usage

// Define a new Enum type
class Status extends Enum {

    const ACTIVE = 'active';

    const PASSIVE = 'pasive';

}

// Use the new Status Enum type
$carStatus = new Status(Status::ACTIVE);
$carStatus->getValue(); // return 'active';

$carStatus2 = new Status();
$carStatus2->setValue(Status::PASSIVE);

if ($carStatus2->isEqualTo($carStatus)) { // it will be false
    echo "\$carStatus2 and \$carStatus has the same value";
} else { // this will be printed
    echo "\$carStatus2 and \$carStatus has different value"; 
    echo "\$carStatus2: $carStatus2"; // print '$carStatus2: passive'
}

Status::isValidValue('active'); // return true
Status::isValidKey('INACTIVE'); // return false
Status::getKeyByValue('passive'); // return 'PASSIVE'
Status::listOptions(); // return ['ACTIVE' => 'active', 'PASSIVE' => 'passive']
Status::listKeys(); // return ['ACTIVE', 'PASSIVE']
Status::listValues(); // return ['active', 'passive']
Status::getDefaultValue(); // return 'active' (it's the first constants value by default, but this method is also overridable)

The Versions

14/03 2017

dev-master

9999999-dev https://github.com/ngabor84/enum

Enum is a simple implementation of php enumeration type.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

14/03 2017

v0.3.2

0.3.2.0 https://github.com/ngabor84/enum

Enum is a simple implementation of php enumeration type.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

13/02 2017

0.2.0

0.2.0.0 https://github.com/ngabor84/enum

Enum is a simple implementation of php enumeration type.

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires