2017 © Pedro Peláez
 

library enum

Enum class.

image

grachevko/enum

Enum class.

  • Tuesday, June 26, 2018
  • by grachevko
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,077 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 18 % Grown

The README.md

PHP Enum implementation

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

Installation

composer require premier/enum

Usage

namespace Premier\Enum;

/**
 * @method static DriveWheel front()
 * @method static DriveWheel rear()
 * @method static DriveWheel allDrive()
 * @method static DriveWheel fromCode(string $code)
 * @method bool   isFront()
 * @method bool   isRear()
 * @method bool   isAllDrive()
 * @method string toCode()
 */
final class DriveWheel extends Enum
{
    private const FRONT = 1;
    private const REAR = 2;
    private const ALL_DRIVE = 3;

    protected static $code = [
        self::FRONT => 'FWD',
        self::REAR => 'RWD',
        self::ALL_DRIVE => 'AWD',
    ];
}

// New instance
$drive = DriveWheel::create(1);
// or
$drive = DriveWheel::front();
// or
$drive = DriveWheel::fromCode('FWD');
// or
$drive = DriveWheel::from('code', 'FWD');

// Array instances
DriveWheel::all(); // [DriveWheel::front(), DriveWheel::rear(), DriveWheel::allDrive()]
DriveWheel::all(['FWD', 'RWD'], $reverse = false, $property = 'code'); // [DriveWheel::front(), DriveWheel::rear()]
DriveWheel::all([1, 2], $reverse = true); // [DriveWheel::allDrive()]

// Methods
$drive->toId();    // 1
$drive->to('id');  // 1
(string) $drive;   // '1'

$drive->toName(); // 'front'

$drive->toCode();   // 'FWD'
$drive->to('code'); // 'FWD'

$drive->isFront(); // true
$drive->isRear();  // false

$drive->eq(DriveWheel::front()); // false
$drive->eq(DriveWheel::rear());  // false

Design

  • All constants MUST be private
  • All constants MUST be type of integer
  • All properties MUST NOT be public
  • All properties MUST be static
  • Properties MUST contain values for all defined constants

Doctrine

This lib distributed with Type class for Doctrine to easy configure each Enum as Doctrine Type., (*2)

Premier\Enum\Doctrine\EnumType::register(Premier\Enum\Gender::class, 'gender_enum', $property = 'id');

class Entity 
{
    /**
    * @var Gender
    * 
    * @ORM\Column(type="gender_enum") 
    */
    public $gender;
}

The Versions

26/06 2018

dev-master

9999999-dev

Enum class.

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=7.1

 

The Development Requires

by Konstantin Grachev

26/06 2018

v0.13.1

0.13.1.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

26/06 2018

v0.13

0.13.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

02/04 2018

v0.12

0.12.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

12/03 2018

v0.11.1

0.11.1.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

05/03 2018

v0.11

0.11.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

28/11 2017

0.10

0.10.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

13/09 2017

0.9

0.9.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

11/04 2017

0.8

0.8.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

24/03 2017

0.7

0.7.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

08/03 2017

0.6

0.6.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

19/02 2017

0.5

0.5.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

18/02 2017

0.4

0.4.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

18/02 2017

0.3.1

0.3.1.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

18/02 2017

0.3

0.3.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7.1
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

18/02 2017

0.2

0.2.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

18/02 2017

0.1

0.1.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=7
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev

27/03 2016

1.0

1.0.0.0

Enum class.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-mbstring *

 

The Development Requires

by Konstantin Grachev