Download the PHP package patchlevel/enum without Composer

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

Mutation testing badge Type Coverage

enum

Small lightweight library to create enum in PHP without SPLEnum and strict comparisons allowed.

dislcaimer

For project that are build on PHP >=8.1 please use the language build in Enums described in this rfc: https://wiki.php.net/rfc/enumerations This library should not be needed anymore and will not support PHP >8.1.

installation

declaration

First of all you have to define your enum. To do this, you have to inherit from the Enum class, create a few constants (the value must be unique and a string) and define methods that return an enum representation. Here is an example:

self::get() ensures that exactly one instance of a representation really exists so that strict comparisons can be used without problems.

Alternatively, you can inherit the ExtendedEnum, which comes with a few conveniences, more about this under ExtendedEnum.

api

work with enum

Strict comparisons are not a problem as it ensures that there is only one instance of a certain value.

fromString

You can create an enum from a string. It is checked internally whether the value is valid, otherwise an InvalidValue exception is thrown.

toString

The other way around, an enum can also be converted back into a string.

equals

The Equals method is just a wrapper for $a === $b.

isValid

isValid can be used to check whether the transferred value is valid. The return value is a boolean.

values

You can also get all Enum instances.

keys

Or all keys.

extended enum

Alternatively, it can also extend from ExtendedEnum. This implementation also provides other features mostly magic methods: __toString, __callStatic and implementing \JsonSerializable.

__callStatic

With the magic method __callStatic it is possible to create an Enum instance based only on the constant names. So no extra method is needed to be defined. If the constant name doesn't exist in the enum a BadMethodCall exception is thrown.

__toString

Just the magic method implementation of toString.

JsonSerializable

The ExtendedEnum already implements the method jsonSerialize from the interface \JsonSerializable. This means that \json_encode will automatically serialize the value in the right manner. Beware that \json_decode won't automatically decode it back into the enum. This job must be tackled manually. See this example:


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
ext-json Version ^7.4|^8.0
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 patchlevel/enum contains the following files

Loading the files please wait ....