Download the PHP package ekvedaras/php-enum without Composer

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

Tests Code Coverage Latest Version on Packagist Total Downloads

Twitter Follow

Big thanks happy-types/enumerable-type for the original idea. Take a look if it suits your needs better.

This package adds meta field, provides a few more methods like options, keys, json, etc. and there are simple php array, illuminate/collection, arrayy and doctrine collection implementations to choose from.

Benefits

Defining enums

Create enums by extending one of:

Integers can be used as IDs instead of string values if you prefer.

Usage

Retrieving and comparing enum values

Accessing value properties

Listing enum values

There are two implementations provided:

PHP array

To use PHP array your enums should extend EKvedaras\PHPEnum\PHPArray\Enum class

Illuminate Collection

Either illuminate/support or illuminate/collections package is required which is not installed by default.

To use Illuminate Collection your enums should extend EKvedaras\PHPEnum\Illuminate\Collection\Enum class.

The only difference is enum, options and keys methods will return Collection instances instead of arrays. The rest works exactly the same.

Meta

Meta field is intentionally left as mixed type as it could be used for various reasons. For example linking enum options with a specific implementation:

Resolving payment handler in Laravel:

Meta could also be used as a more in detail description of each option that could be displayed to users or some other object linking other classes, resources together.

Furthermore, in some cases it is useful to resolve enum option from meta. That is also possible:

Things to know

final public static function

Only methods marked as final public static will be considered as possible values of enum. Other methods are still there, but they will not be returned in enum / keys / options, etc. results and won't be considered as valid values. However, this allows to extend enums and make them more useful. For example:

from($id) only allows valid IDs

Well, this is expected. Calling PaymentMethod::from('ideal') will throw OutOfBoundsException.

No serialization

Enum object instances cannot be serialized. Deserialized objects would get a different address in memory therefore, === would no longer work. Calling serialize(PaymentMethod::stripe()) will throw a RuntimeException.

As a workaround it is better to store the ID instead of object itself. You still get the bonus of setters only accepting valid values.

Don't mix implementations

Enum instances cache is stored in a static variable. Choose one implementation for your project and stick to it, otherwise you may unexpectedly get errors because types don't match.

You may create your own project enum class and extend your chosen implementation, so if it ever needs to be changed it can be done in one place only (if storage APIs match).

Related packages

Changelog

See changes in changelog files:


All versions of php-enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-json 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 ekvedaras/php-enum contains the following files

Loading the files please wait ....