Download the PHP package mimosafa/php-enumeration without Composer

On this page you can find all versions of the php package mimosafa/php-enumeration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-enumeration

PHP Enumeration

日本語のREADMEはこちら

Latest Stable Version License

A powerful PHP 8.1+ library to create inheritable, feature-rich enumerations that extend beyond native enum capabilities.


Why PHP Enumeration?

PHP 8.1 introduced native enumerations, which are a great addition to the language. However, they come with a few limitations:

This package provides a set of base classes and traits to create enumerations that overcome these limitations, offering a more flexible and powerful way to work with enums in your PHP 8.1+ projects.

Key features include:

Comparison with Native PHP Enums

While this library offers powerful features, it's important to understand the differences and choose the right tool for your needs.

Feature / Aspect Native PHP Enums (PHP 8.1+) This Library (mimosafa/php-enumeration)
Inheritance ❌ Not supported ✅ Supported
Flexible Backed Values string or int only ✅ Any scalar (string, int, float, bool)
Instance lookup by name ✅ (Direct static access) ✅ Supported (via ::of() / ::tryOf())
Dynamic Case Definition ❌ Not supported ✅ Supported (via toArray() or EnumerateConstantsTrait)
match Expression ✅ Supported ❌ Not directly supported
Type Hinting enum keyword Class name (e.g., PureEnum, BackedEnum)
Built-in cases() ✅ Supported ✅ Supported (via custom implementation)

Choose this library if you need advanced features like inheritance or flexible backed values. For simpler use cases where match expression support and strict string/int backed values are preferred, native PHP Enums might be sufficient.

Installation

You can install the package via composer:

Usage

Pure Enums

Create a simple enum without backed values. The toArray() method allows for dynamic definition of cases. If you want IDE autocompletion for magic static calls like Status::PUBLISHED(), add @method annotations to the child class PHPDoc as shown below.

Dynamic Case Definition Example:

You can define enum cases dynamically, for instance, by reading file names from a directory:

Backed Enums

Create enums with scalar values. If you want IDE autocompletion for magic static calls like Suit::Diamonds(), add @method annotations to the child class PHPDoc as shown below.

Inheritance with EnumerateConstantsTrait

This is where the magic happens. Define your cases as class constants and use inheritance to build powerful, domain-specific enums.

The EnumerateConstantsTrait automatically turns your class constants into enum cases.

1. Define a base enum:

2. Extend and control the cases:

Now, you can create specialized enums that inherit from UserRole but only expose a subset of the cases.

You can also configure this declaratively with PHP attributes (useful for IDE discoverability):

Available attributes:

3. Use them in your application:

License

The MIT License (MIT). Please see License File for more information.


All versions of php-enumeration with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mimosafa/php-enumeration contains the following files

Loading the files please wait ...