Download the PHP package timetoogo/enums without Composer

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

Enums for PHP 5.4+

Installation

Add package to composer.json.

Or manually require {Path to Enum}/Loader.php

Summary

An introduction

Congrats, we have successfully reimplemented the boolean using enums.

Lets test it out:

Great it works, now lets reimplement ! operator.

And test it out:

Cool, but pointless.

Lets do something useful and create the days of the week (as in summary) :

Notice something? The enum values are simply represented by their method name.

Well, lets keep DRY and see how we go:

Well that didn't do much, and it is still extremely verbose! And ugly.

Relax, there is a solution:

That's better! Note that there will be no difference in functionality between the above three examples.

Note that using the \Enum\Values only works for PHP >5.4.16

If your enums values are represented by the method names, you can utilise the \Enum\Values trait. This trait contains a single static method _. You can alias this method to the required enum values, and the aliased methods will return the enum representing the method name string.

Using this trait the equivalent Boolean would become:

Conversion To String

Override the protected string ToString(mixed $Value) to customize the conversion to string:

Serialization

Enums values can also be fully serialized/unserialized using the Enum\Base::Serialize(Enum\Base $Enum) and Enum\Base::Unserialize(string $SerializedEnum) repectively. This will work for any defined enum.

If you want to un/serialize an enum of a specific type, you can can call either method in the context of the required enum type:

Comparison and Equality

An two enum instances of the same type, representing the same value must be equal. Comparison results using === operator can be seen below.

As you can see, within a enum there is only ever one instance representing any given value.

Clean comprehension API

  • Enum\Base::Map(callable $MappingCallback) Maps the enum instances with the supplied callback
  • Enum\Base::MapValues(callable $MappingCallback) Maps the represented values with the supplied callback
  • Enum\Base::Filter(callable $MappingCallback) Filters the enum instances with the supplied callback
  • Enum\Base::FilterByValue(callable $MappingCallback) Filters the enums by their represented value with the supplied callback
  • Enum\Base::FirstOrDefault(callable $MappingCallback) Returns the first enum according to the filter callback or the default value if none is matched
  • FirstOrDefaultByValue(callable $MappingCallback)

Usage

A more sophisticated example

If your requirements are more complex, enums can represent any serializable value:

We have defined an enum representing some countries and have provided methods to determine information on that data.

Usage


All versions of enums with dependencies

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

Loading the files please wait ....