Skip to content

yar3333/smart-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smart-enum

Build Status Latest Stable Version Total Downloads

A PHP 7.1+ enumeration library. Based on php-enum.

Installation

composer require "smart-enum/smart-enum"

Using

<?php

use SmartEnum\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;
} 

$one = IssueType::ONE(); // $one instanceof IssueType === true

$one1 = IssueType::ONE();
$one2 = IssueType::ONE();
$two = IssueType::TWO();

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

function moveIssue(IssueType $type) {}

$name = $one->getName(); # "ONE"
$one = IssueType::fromName($name);

$value = $one->getValue(); # 1
$new = IssueType::fromValue($value);

$names = IssueType::getNames(); // [ "ONE", "TWO" ]
$values = IssueType::getValues(); // [ 1, 2 ]

$all = IssueType::getAll(); // [ IssueType::ONE(), IssueType::TWO() ]

About

A PHP 7.1+ enumeration library

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages