2017 © Pedro Peláez
 

library php-enum

Enum implementation for PHP 7

image

paillechat/php-enum

Enum implementation for PHP 7

  • Tuesday, July 10, 2018
  • by paillechat
  • Repository
  • 3 Watchers
  • 9 Stars
  • 492 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 10 Versions
  • 36 % Grown

The README.md

Enum

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads, (*1)

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

Why?

To create perfect enums for PHP library, (*3)

Installation

composer require "paillechat/php-enum:^2.0"

Usage

Declare enum class by extending basic Enum and filling it with constants. Constant value does not matter. You can fill it with any payload you can utilize as general constant, but we suggest you to keep constants as protected as possible, (*4)

<?php

use Paillechat\Enum\Enum;

/**
 * These docs are used only to help IDE
 * 
 * @method static static ONE
 * @method static static TWO
 */
class IssueType extends Enum 
{
    protected const ONE = 1;
    protected const TWO = 2;
} 

# Now you can create enum via named static call
/** @var Enum $one */
$one = IssueType::ONE();

# Enums keeps strict equality
$one1 = IssueType::ONE();
$one2 = IssueType::ONE();
$two = IssueType::TWO();

$one1 === $one2;
$one !== $two;

# Enums plays well with built-in functions
\in_array(IssueType::ONE(), [$one, $two], true);

# Enums plays well with signature type checks
function moveIssue(IssueType $type) {
    if ($type === IssueType::ONE()) {
        throw new \LogicException();
    }

    // ....
}

# You can convert enum to name and back
$name = $one->getName();
$new = IssueType::$name();

The Versions

10/07 2018

dev-master

9999999-dev

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Pavel Batanov
by Ilya Burtsev

enum

10/07 2018

2.1

2.1.0.0

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Pavel Batanov
by Ilya Burtsev

enum

10/07 2018

dev-release/1.x

dev-release/1.x

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

10/07 2018

1.2

1.2.0.0

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

16/04 2018

2.0

2.0.0.0

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Pavel Batanov
by Ilya Burtsev

enum

09/01 2018

1.1

1.1.0.0

Enum implementation for PHP 7

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

07/04 2017

1.0.3

1.0.3.0

Enum implementation for PHP 7

  Sources   Download

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

06/04 2017

1.0.2

1.0.2.0

Enum implementation for PHP 7

  Sources   Download

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

06/04 2017

1.0.1

1.0.1.0

Enum implementation for PHP 7

  Sources   Download

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum

06/04 2017

1.0.0

1.0.0.0

Enum implementation for PHP 7

  Sources   Download

The Requires

  • php >=7.0.0

 

The Development Requires

by Ilya Burtsev

enum