2017 © Pedro Peláez
 

library php-simple-enum

Provides a simple enum and flag enum for PHP.

image

chadsikorra/php-simple-enum

Provides a simple enum and flag enum for PHP.

  • Sunday, May 28, 2017
  • by ChadSikorra
  • Repository
  • 1 Watchers
  • 3 Stars
  • 23,676 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 33 % Grown

The README.md

php-simple-enum

Provides a simple enum and flag enum for PHP using traits and interfaces., (*1)

A simple enum example:, (*2)

use Enums\SimpleEnumInterface;
use Enums\SimpleEnumTrait;

class DayOfWeek implements SimpleEnumInterface
{
    use SimpleEnumTrait;

    const Monday = 1;

    const Tuesday = 2;

    const Wednesday = 3;

    const Thursday = 4;

    const Friday = 5;

    const Saturday = 6;

    const Sunday = 7;
}

// Get all of the names
var_dump(DayOfWeek::names());

// Get all of the values
var_dump(DayOfWeek::values());

// View it as an array
var_dump(DayOfWeek::toArray());

// Check if a name is valid. This is case insensitive.
if (DayOfWeek::isValidName('Monday')) {
    // ...
}

// Check if a value is valid.
if (DayOfWeek::isValidValue(DayOfWeek::Monday)) {
    // ...
}

// Get the name for a specific value.
var_dump(DayOfWeek::getValueName(1));

// Get the value for a specific name. This is case insensitive.
var_dump(DayOfWeek::getNameValue('Monday'));

A flag enum example:, (*3)

use Enums\FlagEnumInterface;
use Enums\FlagEnumTrait;

class FilePermission implements FlagEnumInterface
{
    use FlagEnumTrait;

    const Read = 1;

    const Write = 2;

    const Execute = 4;
}

$permission = new FilePermission(FilePermission::Read | FilePermission::Write);

// Remove a permission
$permission->remove('Write');

// Add a permission
$permission->add('Execute');

// Check for a permission
if ($permission->has('Read')) {
    // ...
}

// Get the flag value
var_dump($permission->getValue());

// Get all of the names for the flag as an array
var_dump($permission->getNames());

// View the string representation (comma delimited list)
var_dump((string) $permission);

The static methods are available in both the simple and flag enums., (*4)

The Versions

28/05 2017

dev-master

9999999-dev https://github.com/ChadSikorra/php-simple-enum

Provides a simple enum and flag enum for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

enum

28/05 2017

1.0.0

1.0.0.0 https://github.com/ChadSikorra/php-simple-enum

Provides a simple enum and flag enum for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

enum