Download the PHP package mle86/enum without Composer

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

php-enum

Build Status Coverage Status Latest Stable Version PHP 7.1 License

This PHP library provides enum functionality for PHP 7.1+ with an Enum interface, an AbstractEnum base class, and an AbstractAutoEnum base class.

It is released under the MIT License.

Installation and Dependencies:

Via Composer: $ composer require mle86/enum

Or insert this into your project's composer.json file:

Its only dependency is the mle86/value library.

Minimum PHP Version:

PHP 7.1

Usage:

To implement a custom Enum class, simply extend the AbstractAutoEnum base class and add a few public constants:

For more fine control over which values are considered valid by your class, override the isValid() class method or extend the more general AbstractEnum base class instead.
Keep in mind though that enum classes are fundamentally based on a hardcoded list of accepted values known at compile-time; if you want to accept values based on a pattern or on complex validation logic, consider using a value object class such as Value instead.

There's three ways to use enum classes:

  1. Just use the class constants.
    You don't really need this library to do that as you can simply write a standalone class for that, but it's definitely a possibility.

  2. Build instances and use typehints in your methods.
    The AbstractAutoEnum base classes have a default constructor and wraps a single valid enum value in the instance. The wrapped value can then be retrieved with the value() getter but it's also returned by the default __toString() and jsonSerialize() methods.

  3. Use the validate() and validateOptional() methods to enfore correct types in your methods.
    If you don't want to build instances of your enum classes to avoid the object overhead or simply because you receive non-object input values (e.g. from a JSON API), you can also check raw input values with the two validate methods. They will accept both raw values and instances, return void, and throw an EnumValueException if the input is invalid. The validateOptional() method also accepts NULL values.

An example with instances and enum typehints:

Another example without typehints and more explicit validation:

Classes and Interfaces:

More Documentation:


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
mle86/value Version ^2.1 || ^1.2
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 mle86/enum contains the following files

Loading the files please wait ....