Download the PHP package rexlabs/enum without Composer

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

Deprecated

Warning If you are using PHP 8.1 or higher, we recommend you use native php enums in place of this package.

We may release some maintenance patches but support for this package is otherwise being discontinued.

Feel free to fork our code and adapt it to your needs.

Enum PHP Library

License: MIT Packagist

Overview

This library provides an Enum / Enumeration implementation for PHP.

Why use this library

Usage

First create a new class that extends \Rexlabs\Enum\Enum and do the following;

  1. Declare your constants
  2. Optional: provide a map() method:

Example

Dependencies

Installation

To install in your project:

Type-hinting

Now you can type-hint your Enum object as a dependency:

Instance Methods

Each instance of Enum provides the following methods:

name()

Returns the constant name.

key()

Returns the value/key assigned to the constant in the const MY_CONST = 'key' declaration.

value()

Returns the value (if-any) that is mapped (in the array returned by map()). If no value is mapped, then this method returns null.

is(Enum|string $compare)

Returns true if this instance is the same as the given constant key or enumeration instance.

__toString()

The __toString() method is defined to return the constant name.

Static Methods

map()

Returns an array which maps the constant keys to a value. This method can be optionally implemented in a sub-class. The default implementation returns an array of keys mapped to null.

instances()

Returns an array of Enum instances.

keys()

Returns an array of constant keys.

values()

Returns an array of values defined in map(). If map() is not implemented then an array of null values will be returned.

names()

Returns an array of all the constant names declared with the class.

namesAndKeys()

Returns an associative array of CONSTANT_NAME => key, for all the constant names declared within the class.

keyForName(string $name)

Returns the key for the given constant name.

nameForKey(string $key)

Returns the constant name for the given key (the inverse of keyForName).

valueForKey(string $key)

Returns the value (or null if not mapped) for the given key (as declared in the map() method).

keyForValue(mixed $value)

Returns the key for the given value (as declared in the map() method).

Note: If duplicate values are contained within the map() method then only the first key will be returned.

instanceFromName($name)

Create instance of this Enum from the given constant name.

instanceFromKey($key)

Create instance of this Enum from the given key.

isValidKey(string $key)

Returns true if the given key exists.

isValidName(string $name)

Returns true if the given constant name (case-sensitive) has been declared in the class.

requireValidKey(string $key)

Throws a \Rexlabs\Enum\Exceptions\InvalidKeyException if the given key does NOT exist.

Tests

To run tests:

To run coverage report:

Coverage report is output to ./tests/report/index.html

Contributing

Contributions are welcome, please submit a pull-request or create an issue. Your submitted code should be formatted using PSR-1/PSR-2 standards.

About


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0 <8.3
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 rexlabs/enum contains the following files

Loading the files please wait ....