Download the PHP package fpoirotte/enum-trait without Composer
On this page you can find all versions of the php package fpoirotte/enum-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download fpoirotte/enum-trait
More information about fpoirotte/enum-trait
Files in fpoirotte/enum-trait
Download fpoirotte/enum-trait
More information about fpoirotte/enum-trait
Files in fpoirotte/enum-trait
Vendor fpoirotte
Package enum-trait
Short Description Enumeration type for PHP using traits
License MIT
Homepage https://github.com/fpoirotte/EnumTrait
Package enum-trait
Short Description Enumeration type for PHP using traits
License MIT
Homepage https://github.com/fpoirotte/EnumTrait
Keywords enumenumeration
Please rate this library. Is it a good library?
Informations about the package enum-trait
Enumeration type for PHP
This component provides an actual enumeration type for PHP.
Installation
This component relies on Composer for its installation.
To use the Enum Trait in your project, just add a requirement on the package:
$ php composer.php require fpoirotte/enum-trait
Usage
Use the following snippet to declare a new enumeration:
Goals
This component was designed to achieve the following goals:
- Define a true type for enumerations, so they can serve as type-hints : .. sourcecode:: php
- Make it possible to extend an existing enum to add new values.
This is made dead easy by class inheritance.
Preventing this is also easy thanks to the
final
keyword. - Remove the need for an actual value. Intrinsically, a label ought to be enough to figure out the meaning of a specific enum instance. This also avoids repetition. Say goodbye to the following idiom: .. sourcecode:: php
- Turn enumeration values into opaque values.
This is actually a consequence from the previous goal.
This prevents developers from using the value directly, eg.
if ($enumValue == 1) { /* ... */ }
, which in turn prevents subtle bugs whenever the underlying value/type evolves. - Make it possible to compare enumeration values directly, without the need for helper methods. See Usage for an example of that.
- Make it possible to easily serialize/unserialize enumerations (without requiring some helper functions).
- Make it possible to copy (clone) an enumeration value without a specific support function.
- Add no requirements on additional PHP extensions (eg.
SplTypes
).
Contributions
To contribute a patch:
- Fork this project
- Prepare your patch
- Submit a pull request
License
This project is released under the MIT license. See the LICENSE file for more information.
All versions of enum-trait with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.4
ext-reflection Version *
ext-reflection Version *
The package fpoirotte/enum-trait contains the following files
Loading the files please wait ....