Download the PHP package marc-mabe/php-enum without Composer

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

php-enum

Build Status Code Coverage License Latest Stable Total Downloads Monthly Downloads Dependents

This is a native PHP implementation to add enumeration support to PHP. It's an abstract class that needs to be extended to use it.

What is an Enumeration?

Wikipedia

In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but which do not have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

Usage

Basics

Type-Hint

Type-Hint issue

Because in normal OOP the above example allows UserStatus and types inherited from it.

Please think about the following example:

Now the setter receives a status it doesn't know about but allows it.

Solution 1: Finalize the enumeration

`

But as this library emulates enumerations it has a few downsides:

Solution 2: Using Enum::get()

But of course this solution has downsides, too:

EnumSet

An EnumSet is a specialized Set implementation for use with enumeration types. All of the enumerators in an EnumSet must come from a single enumeration type that is specified, when the set is created.

Enum sets are represented internally as bit vectors. The bit vector is either an integer type or a binary string type depending on how many enumerators are defined in the enumeration type. This representation is extremely compact and efficient. Bulk operations will run very quickly. Enumerators of an EnumSet are unique and ordered based on its ordinal number by design.

It implements IteratorAggregate and Countable to be directly iterable with foreach and countable with count().

The EnumSet has a mutable and an immutable interface. Mutable methods start with set, add or remove while immutable methods start with with.

EnumMap

An EnumMap maps enumerators of the same type to data assigned to.

It implements ArrayAccess, Countable and IteratorAggregate so elements can be accessed, iterated and counted like a normal array using $enumMap[$key], foreach and count().

Serializing

Because this enumeration implementation is based on a singleton pattern and in PHP it's currently impossible to unserialize a singleton without creating a new instance this feature isn't supported without any additional work.

As of it's an often requested feature there is a trait that can be added to your enumeration definition. The trait adds serialization functionallity and injects the unserialized enumeration instance in case it's the first one. This reduces singleton behavior breakage but still it beaks if it's not the first instance and you could result in two different instance of the same enumeration.

Use it with caution!

PS: EnumSet and EnumMap are serializable by default as long as you don't set other non-serializable values.

Example of using EnumSerializableTrait

Generics and Static Code Analyzer

With version 4.3 we have added support for generics and added better type support.

Generic types will be detected by PHPStan and Psalm.

Additionally, we have developed an extension for PHPStan to make enumerator accessor methods known.

Why not SplEnum

Changelog

Changes are documented in the release page.

Install

Composer

Add marc-mabe/php-enum to the project's composer.json dependencies and run php composer.phar install

GIT

git clone git://github.com/marc-mabe/php-enum.git

ZIP / TAR

Download the last version from Github and extract it.

Versioning and Releases

This project follows SemVer specification.

There are no LTS releases and we don't have (fixed) time based release windows. Instead releases happen as necessary.

We do support at least all maintained PHP versions.

Bug fixes will be backported to the latest maintained minor release.

Critical bug fixes and security relates fixes can also be backported to older releases.

Release Status PHP-Version
1.x EOL >=5.3
2.x EOL >=5.3 & HHVM<4
3.x EOL >=5.6 & HHVM<4
4.x active >=7.1

New BSD License

The files in this archive are released under the New BSD License. You can find a copy of this license in LICENSE.txt file.


All versions of php-enum with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1 | ^8.0
ext-reflection Version *
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 marc-mabe/php-enum contains the following files

Loading the files please wait ....