PHP 8.1 like legacy enum (Experimental Alpha Version)

Overview

flux-legacy-enum

PHP 8.1 like legacy enum

Experimental Alpha Version

Installation

COPY --from=docker-registry.fluxpublisher.ch/flux-enum/legacy:latest /flux-legacy-enum /%path%/libs/flux-legacy-enum
require_once __DIR__ . "/%path%/libs/flux-legacy-enum/autoload.php";

Examples

Unit

Native

enum Enum1
{
    case A;
    case B;
    case C;
}
Enum1::A->name === "A";
Enum1::A instanceof Enum1;
Enum1::A === Enum1::A;

Enum1::cases();

try { Enum1::D; } catch (Throwable $ex) { }

Library

/**
 * @method static static A()
 * @method static static B()
 * @method static static C()
 */
class Enum1 extends LegacyUnitEnum
{

}
Enum1::A()->name === "A";
Enum1::A() instanceof Enum1;
Enum1::A() === Enum1::A();

Enum1::cases();

try { Enum1::D(); } catch (Throwable $ex) { }

String Backed

Native

enum Enum2: string
{
    case NAME_1 = "value_1";
    case NAME_2 = "value_2";
    case NAME_3 = "value_3";
}
Enum2::NAME_1->name === "NAME_1";
Enum2::NAME_1->value === "value_1";
Enum2::NAME_1 instanceof Enum2;
Enum2::NAME_1 === Enum2::NAME_1;
json_encode(Enum2::NAME_1) === '"value_1"';

Enum2::cases();

Enum2::tryFrom("value_2") === Enum2::NAME_2;
Enum2::tryFrom("xyz") === null;

Enum2::from("value_3") === Enum2::NAME_3;

try { Enum2::NAME_4; } catch (Throwable $ex) { }
try { Enum2::from("xyz"); } catch (Throwable $ex) { }

Library

/**
 * @method static static NAME_1() value_1
 * @method static static NAME_2() value_2
 * @method static static NAME_3() value_3
 */
class Enum2 extends LegacyStringBackedEnum
{

}
Enum2::NAME_1()->name === "NAME_1";
Enum2::NAME_1()->value === "value_1";
Enum2::NAME_1() instanceof Enum2;
Enum2::NAME_1() === Enum2::NAME_1();
json_encode(Enum2::NAME_1()) === '"value_1"';

Enum2::cases();

Enum2::tryFrom("value_2") === Enum2::NAME_2();
Enum2::tryFrom("xyz") === null;

Enum2::from("value_3") === Enum2::NAME_3();

try { Enum2::NAME_4(); } catch (Throwable $ex) { }
try { Enum2::from("xyz"); } catch (Throwable $ex) { }

Int Backed

Native

enum Enum3: int
{
    case ONE = 1;
    case TWO = 2;
    case THREE = 3;
}
Enum3::ONE->name === "ONE";
Enum3::ONE->value === 1;
Enum3::ONE instanceof Enum3;
Enum3::ONE === Enum3::ONE;
json_encode(Enum3::ONE) === '1';

Enum3::cases();

Enum3::tryFrom(2) === Enum3::TWO;
Enum3::tryFrom(4) === null;

Enum3::from(3) === Enum3::THREE;

try { Enum3::FOUR; } catch (Throwable $ex) { }
try { Enum3::from(4); } catch (Throwable $ex) { }

Library

/**
 * @method static static ONE() 1
 * @method static static TWO() 2
 * @method static static THREE() 3
 */
class Enum3 extends LegacyIntBackedEnum
{

}
Enum3::ONE()->name === "ONE";
Enum3::ONE()->value === 1;
Enum3::ONE() instanceof Enum3;
Enum3::ONE() === Enum3::ONE();
json_encode(Enum3::ONE()) === '1';

Enum3::cases();

Enum3::tryFrom(2) === Enum3::TWO();
Enum3::tryFrom(4) === null;

Enum3::from(3) === Enum3::THREE();

try { Enum3::FOUR(); } catch (Throwable $ex) { }
try { Enum3::from(4); } catch (Throwable $ex) { }

Mix

interface Enum4 extends StringBackedEnumValue
{

}
enum NativeEnum4: string implements Enum4
{
    case A = "a";
    case B = "b";
    case C = "c";
}
/**
 * @method static static A() a
 * @method static static B() b
 * @method static static C() c
 */
class LegacyEnum4 extends LegacyStringBackedEnum implements Enum4
{

}
function abc(Enum4 $enum4) : void
{
    $enum4->value === "a";
}

abc(NativeEnum4::A);
abc(LegacyEnum4::A());
You might also like...
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

Unofficial Firebase Admin SDK for PHP

Firebase Admin PHP SDK Table of Contents Overview Installation Documentation Support License Overview Firebase provides the tools and infrastructure y

Simple utility and class library for generating php classes from a wsdl file.

wsdl2phpgenerator Simple WSDL to PHP classes converter. Takes a WSDL file and outputs class files ready to use. Uses the MIT license. Announcement: We

Content Negotiation tools for PHP.

Negotiation Negotiation is a standalone library without any dependencies that allows you to implement content negotiation in your application, whateve

A PHP library to support implementing representations for HATEOAS REST web services.

Hateoas A PHP library to support implementing representations for HATEOAS REST web services. Installation Working With Symfony Usage Introduction Conf

This PHP library will help you to work with your Pinterest account without using any API account credentials.
This PHP library will help you to work with your Pinterest account without using any API account credentials.

Pinterest Bot for PHP A PHP library to help you work with your Pinterest account without API credentials. The Pinterest API is painful: receiving an a

Pure PHP implementation of GraphQL Server – Symfony Bundle

Symfony GraphQl Bundle This is a bundle based on the pure PHP GraphQL Server implementation This bundle provides you with: Full compatibility with the

application/hal builder / formatter for PHP 5.4+

Nocarrier\Hal This is a library for creating documents in the application/hal+json and application/hal+xml hypermedia formats It requires PHP 5.4 or l

PHP REST API Framework

PSX Framework About PSX is a framework written in PHP dedicated to build REST APIs. It is based on multiple components which cover many aspects of the

Releases(v2022-12-12-1)
Owner
fluxlabs
Your innovator and motivator for dynamic software solutions - Pre docker image builds available on https://docker-registry.fluxpublisher.ch
fluxlabs
Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)

chargebee-php-sdk Overview This package provides an API client for Chargebee subscription management services. It connects to Chargebee REST APIs for

GLOBALIS media systems 8 Mar 8, 2022
Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration

forms Modern version of pocketmine forms API, ported to PHP 8.0+ with high quality code and phpstan integration Code samples ModalForm Using ModalForm

Frago9876543210 23 Nov 18, 2022
PHP library/SDK for Crypto APIs 2.0 using Guzzle version 7

cryptoapis/sdk-guzzle7 Crypto APIs 2.0 is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain an

Crypto APIs 3 Oct 21, 2022
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Simple PHP API v.1.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses a

Edson M. de Souza 14 Nov 18, 2021
Doctrine-like fixtures integration for Shopware 6.

Shopware 6 Fixtures Did you ever want to create and load Doctrine-like fixtures in your Shopware 6 plugin? Look no further! This plugin provides an ul

Familiy Office 0 Oct 29, 2021
Like FormRequests, but for validating against a json-schema

JSON Schema Request Laravels Form Request Validation for JSON Schema documents Installation composer require wt-health/laravel-json-schema-request Us

Webtools Health 1 Feb 3, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel

symbiota-api API for Symbiota using the Lumen PHP PHP Micro-Framework By Laravel Laravel Lumen Official Documentation Documentation for the Lumen fram

Biodiversity Knowledge Integration Center 2 Jan 3, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
Single file PHP script that adds a REST API to a SQL database

PHP-CRUD-API Single file PHP script that adds a REST API to a MySQL/MariaDB, PostgreSQL, SQL Server or SQLite database. NB: This is the TreeQL referen

Maurits van der Schee 3.2k Jan 8, 2023