Download the PHP package bakame/aide-enums without Composer

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

Aide for Enums

A collection of traits and classes to improve handling PHP's Enum.

[!CAUTION]
Sub-split of Aide for Enum helpers.
⚠️ this is a sub-split, for pull requests and issues, visit: https://github.com/bakame-php/aide

Installation

Composer

composer require bakame-php/aide-enums

System Requirements

You need:

Usage

Traits

Factory

Enable creating Pure or Backed Enum based on their name. The trait adds two (2) new static methods, tryFromName and fromName and re-introduce the tryFrom and from method on pure Enums. Once added to your Enum you can do the following:

You need the Bakame\Aide\Enum\Factory trait to expose the new API.

Info

Gather information regarding the current Enum via public static methods. This trait enables getting:

You need the Bakame\Aide\Enum\Info trait to expose the new API.

Hasser/Isser methods

Enables asking whether some data are present in the Enum

hasValue and hasCase will always return false for a Pure enumeration.

You need the Bakame\Aide\Enum\Hasser trait to expose the new API.

Comparison

The Compare trait which adds four (4) methods to compare Enums instances. The equals and notEquals methods do strict comparison whereas isOneOf and isNotOneOf do loose comparison taking into account the value or the name of the Enum.

You need the Bakame\Aide\Enum\Compare trait to expose the new API.

Convert

The Convert trait adds three (3) methods to convert Enums instances. The toAssociative converts the Enum instance into an associative array whereas the toJavaScriptObject and toJavaScriptClass methods convert the Enum into a JavaScript equivalent structure.

You need the Bakame\Aide\Enum\Convert trait to expose the new API.

All in one

If you want to apply all the traits together just use the single one which encompass all the traits already mentioned Bakame\Aide\Enum\Helper. Once added to your enum all the methods described here will be made available to your codebase.

You need the Bakame\Aide\Enum\Helper to expose the new API.

Converting the Enum into a JavaScript structure

While the Convert::toJavaScriptObject and Convert::toJavaScriptClass methods are enough to convert your Enum to JavaScript code, behind the scene the method makes use of the JavaScriptConverter class. The class enables returning a more fine-tuned representation that suite your constraints better.

Because there are two (2) ways to create an Enum like structure in JavaScript, the class provides two (2) methods to allow the conversion.

In both cases, the conversion is configurable via wither methods to control the formatting and the JavaScript structure properties.

Backed Enum

For instance, given I have the following enum:

It can be converted into an object using the convertToObject method:

will produce the following JavaScript code snippet:

conversely using convertToClass as follows:

will produce the following JavaScript code snippet:

Of course there are ways to improve the output depending on your use case you can

Here's a more advance usage of the converter to highlight how you can configure it.

will return the following JavaScript code:

Pure Enum

For Pure PHP Enum, the converter will assign a unique Symbol value for each case, starting wih the Symbol(0) and following the PHP order of case declaration. you can optionally configure the start value using the startAt method.

Let's take the following PHP Pure Enum:

It can be converted into an object using the convertToObject method:

will produce the following JavaScript code snippet:

If you set up the starting value to increment you will get a different value:

Then the start at value will be taken into account as shown below:

[!CAUTION]
For Pure Enum the ignoreSymbol and useSymbol methods have no effect on the output.

Storing the output

The converter will not store the resulting string into a Javascriot file as this part is left to the discretion of the implementor. There are several ways to do so:

Credits


All versions of aide-enums with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 bakame/aide-enums contains the following files

Loading the files please wait ....