Download the PHP package jac/enums without Composer

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

Build Status psalm Coverage Status Mutation testing badge

Enum implementation for PHP

Why

To avoid to have to install the SplEnum, yet another extension...

Enums have a lot of benefits (in my own opinion):

In this implementation the constructor is made private to avoid duplicating instance of the enum

Installation

How to use

For more complex example look at the example directory

Create an Enum

Usage

Enum having multiple keys with the same value[Multiple]

Instantiate an Enum from its value is possible calling the Devise::EUR() for example, and having multiple keys with the same value won't be harmful in that case. However, it is different when we try to instantiate an Enum from its value. Let's take the following example:

There is multiple ways a developer could use to help the builder decide which key should be preferred.

  1. Use the __DEFAULT__ constant which is a reverted key => value array. This method will first be checked before the following two
  2. Use the @default tag in the php doc associated to the constant, in the above example, for the chinese devise (RMB, CNY), in case we use Devise::from('RMB'), the key RMB is going to be choose.
  3. Use the @deprecated to exclude values. When a constant is set as deprecated, then its priority is lowered and it will be returned if and only if no other options is found.

In case there is no configuration set for the default value to choose or if there is still multiple value available, a warning is triggered and one of the found options is returned.

API

Comparison of enums works with == and ===

Static method

Serialization

The enum implements the JsonSerializable interface. By default it will return the value as a string

A formatter is available: Jac\Enum\EnumJsonFormat with several option implemented.

Will output

Will output


All versions of enums with dependencies

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

Loading the files please wait ....