2017 © Pedro Peláez
 

library enum

A PHP 5.4+ enumeration library.

image

commerceguys/enum

A PHP 5.4+ enumeration library.

  • Saturday, May 23, 2015
  • by bojanz
  • Repository
  • 6 Watchers
  • 91 Stars
  • 1,031,488 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 5 Forks
  • 2 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

enum

Build Status, (*1)

A PHP 5.4+ enumeration library., (*2)

Class constants are frequently used to denote sets of allowed values. By grouping them in an enumeration class, we gain the ability to add helper methods, list all possible values and validate values against them., (*3)

A commerceguys/addressing example:, (*4)

namespace CommerceGuys\Addressing\Enum;

use CommerceGuys\Enum\AbstractEnum;

/**
 * Enumerates available locality types.
 */
final class LocalityType extends AbstractEnum
{
    const CITY = 'city';
    const DISTRICT = 'district';

    // We can provide a getDefault() method here, or anything else.
}

LocalityType::getAll(); // ['CITY' => 'city', 'DISTRICT' => 'district']
LocalityType::getKey('city'); // 'CITY'
LocalityType::exists('city'); // true
LocalityType::assertExists('invalid value'); // InvalidArgumentException
LocalityType::assertAllExist(['district', 'invalid value']); // InvalidArgumentException

Meanwhile, on the AddressFormat:, (*5)

// The AddressFormatInterface is now free of LOCALITY_TYPE_ constants.
class AdressFormat implements AddressFormatInterface
{
    public function setLocalityType($localityType)
    {
        LocalityType::assertExists($localityType);
        $this->localityType = $localityType;
    }
}

The reason why this library was made instead of reusing myclabs/php-enum was that we didn't want to allow enumerations to be instantiated., (*6)

The Versions

23/05 2015

dev-master

9999999-dev

A PHP 5.4+ enumeration library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bojan Zivanovic

27/02 2015

v1.0

1.0.0.0

A PHP 5.4+ enumeration library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bojan Zivanovic