Download the PHP package fab2s/enumerate without Composer

On this page you can find all versions of the php package fab2s/enumerate. 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 enumerate

Enumerate

QA CI codecov Packagist Version PRs Welcome License

A lightweight PHP library that makes native enums practical for real-world applications.

The Problem

PHP 8.1 enums are powerful but have limitations that create friction in production code:

The Solution

Enumerate provides a unified API to work with any enum type consistently:

Installation

Requirements: PHP 8.1+

Quick Start

Add the trait to your enum:

Now you can:

API Reference

Instantiation Methods

Method Returns Throws Description
tryFromAny($value, $strict = true) ?static - Safe instantiation from any type
fromAny($value, $strict = true) static InvalidArgumentException Strict instantiation
tryFromName($name) ?static - Match by case name
fromName($name) static InvalidArgumentException Strict match by case name

Value Methods

Method Returns Description
toValue() int\|string Get the backed value (or case name for UnitEnum)
jsonSerialize() int\|string Same as toValue(), implements JsonSerializable

Comparison Methods

Method Returns Description
equals(...$values) bool Strict match against provided values
compares(...$values) bool Loose match, allows cross-enum comparison by value

Type Inspection (Static Helper Only)

Method Returns Description
Enumerate::getType($enum) ?string Returns 'string', 'int', or null
Enumerate::isStringBacked($enum) bool Check if string-backed
Enumerate::isIntBacked($enum) bool Check if int-backed
Enumerate::isBacked($enum) bool Check if backed (not UnitEnum)

Detailed Usage

Safe Instantiation with tryFromAny

The native tryFrom() only accepts the exact backing type. tryFromAny() handles real-world input:

Cross-Enum Matching

When migrating between enum versions or comparing related enums, use non-strict mode:

Working with UnitEnums

UnitEnums (no backing value) are matched by case name:

Comparison Methods

Using the Static Helper

All methods are also available via the Enumerate static class, useful when you can't modify the enum:

Real-World Examples

Form Request Handling

Database Model Casting

API Response

Why This Exists

PHP enums prioritize type safety over practicality. While philosophically sound, this creates boilerplate in real applications where enums must interoperate with HTTP requests (always strings), databases, and JSON APIs.

Enumerate handles this complexity internally so you don't have to write defensive code everywhere enums cross system boundaries.

Contributing

Contributions are welcome. Please open issues and submit pull requests.

License

Enumerate is open-source software licensed under the MIT license.


All versions of enumerate 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 fab2s/enumerate contains the following files

Loading the files please wait ...