Download the PHP package eloquent/enumeration without Composer

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

No longer maintained

This package is no longer maintained. See this statement for more info.

Enumeration

An enumeration implementation for PHP.

Current version image Current build status image Current coverage status image

Installation

What is an Enumeration?

In terms of software development, an enumeration (or "enumerated type") is essentially a fixed set of values. These values are called "members" or "elements".

An enumeration is used in circumstances where it is desirable to allow an argument to be only one of a particular set of values, and where anything else is considered invalid.

A basic example

Enumeration can be used like C++ enumerated types. Here is an example, representing a set of HTTP request methods:

This class can now be used in a type hint to easily accept any valid HTTP request method:

Accessing enumeration members

Members are accessed by static method calls, like so:

For each member of the enumeration, a single instance of the enumeration class is instantiated (that is, an instance of HttpRequestMethod in the above example). This means that strict comparison (===) can be used to determine which member has been passed to a function:

Java-style enumerations

Java's enum types have slightly more functionality than C++ enumerated types. They can have additional properties and/or methods, and are really just a specialised kind of class where there are a fixed set of instances.

This is sometimes called the Multiton pattern, and in fact, all enumerations in this implementation are Multitons. The AbstractEnumeration class simply defines its members based upon class constants.

Here is an example borrowed from the Java documentation for its enum types. The following multiton describes all of the planets in our solar system, including their masses and radii:

The above class can be used to take a known weight on earth (in any unit) and calculate the weight on all of the planets (in the same unit):

If the above script is executed, it will produce something like the following output:

Enumerations and class inheritance

When an enumeration is defined, the intent is usually to define a set of valid values that should not change, at least within the lifetime of a program's execution.

Since PHP has no in-built support for enumerations, this library implements them as regular PHP classes. Classes, however, allow for much more extensibility than is desirable in a true enumeration.

For example, a naive enumeration implementation might allow a developer to extend the HttpRequestMethod class from the examples above (assuming the final keyword is removed):

The problem with this scenario is that all the code written to expect only the HTTP methods defined in HttpRequestMethod is now compromised. Anybody can extend HttpRequestMethod to add custom values, essentially voiding the reason for defining HttpRequestMethod in the first place.

This library provides built-in protection from these kinds of circumstances. Attempting to define an enumeration that extends another enumeration will result in an exception being thrown, unless the 'base' enumeration is abstract.

Abstract enumerations

Assuming that there really is a need to extend HttpRequestMethod, the way to go about it is to define an abstract base class, then extend this class to create the desired concrete enumerations:

In this way, when a developer uses a type hint for HttpRequestMethod, there is no chance they will ever receive the 'PATCH' method:


All versions of enumeration with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 eloquent/enumeration contains the following files

Loading the files please wait ....