2017 © Pedro Peláez
 

library php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

image

garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  • Friday, November 13, 2015
  • by garoevans
  • Repository
  • 4 Watchers
  • 18 Stars
  • 11,936 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 13 Versions
  • 9 % Grown

The README.md

Garoevans Php Enum Build Status

This gives us a convenient way to always have an Enum object available and utilise Spl Types if available. It does kick up a bit of a fuss in some IDEs as it sees two classes with the same name, but we know this isn't an issue as the code is fine and dandy :), (*1)

We also wrap the SplEnum class to stop IDEs thinking that the constructor parameters are necessary. Force it to act like the documentation says it should., (*2)

The replacement is so closely tied to the expected usage of the Spl Enum that you could just use the http://php.net/manual/en/class.splenum.php documentation;, (*3)

use Garoevans\PhpEnum\Enum;

class Fruit extends Enum
{
    // If no value is given during object construction this value is used
    const __default = self::APPLE;
    // Our enum values
    const APPLE     = 1;
    const ORANGE    = 2;
}

$myApple  = new Fruit();
$myOrange = new Fruit(Fruit::ORANGE);
$fail     = 1;

function eat(Fruit $aFruit)
{
    if ($aFruit->is(Fruit::APPLE)) {
        echo "Eating an apple.\n";
    } else if ($aFruit->is(Fruit::ORANGE)) {
        echo "Eating an orange.\n";
    }
}

// Eating an apple.
eat($myApple);
// Eating an orange.
eat($myOrange);

// PHP Catchable fatal error:  Argument 1 passed to eat() must be an
// instance of Fruit, integer given
eat($fail);

Apart from normalizing the Spl Enum construct there are additions including a shorthand way of instantiating via a static method named the same as the desired constant. Using the Fruit class from above we can do the following;, (*4)

// Eating an apple.
eat(Fruit::APPLE());

Also, the constantExists() method is available for use;, (*5)

$fruit = new Fruit();
if ($fruit->constantExists("apple")) {
    echo "Apple is available.\n";
}

The Versions

13/11 2015

dev-garoevans-patch-1

dev-garoevans-patch-1 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Gareth Evans

php enum type enumeration splenum

21/07 2015

dev-improvements

dev-improvements https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Gareth Evans

php enum type enumeration splenum

10/10 2014

dev-master

9999999-dev https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Gareth Evans

php enum type enumeration splenum

10/10 2014

dev-develop

dev-develop https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Gareth Evans

php enum type enumeration splenum

10/10 2014

1.2.0

1.2.0.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Gareth Evans

php enum type enumeration splenum

17/10 2013

1.1.4

1.1.4.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

26/08 2013

v1.1.3

1.1.3.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

 

by Gareth Evans

php enum type enumeration splenum

22/08 2013

v1.1.2

1.1.2.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

10/05 2013

v1.1.1

1.1.1.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

10/05 2013

v1.1.0

1.1.0.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

05/02 2013

v1.0.2

1.0.2.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

MIT

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

05/02 2013

v1.0.1

1.0.1.0 https://github.com/garoevans/php-enum

Convenient way to always have an Enum object available and utilise Spl Types if available.

  Sources   Download

The Requires

  • php >=5

 

by Gareth Evans

php enum type enumeration splenum

05/02 2013

v1.0.0

1.0.0.0 https://github.com/garoevans/php-enum

  Sources   Download

by Gareth Evans

php enum type enumeration splenum