Download the PHP package femastudios/enums without Composer

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

A highly flexible and customizable enum library for PHP.

It provides a Java-flavored enumeration in PHP.

Installation

Available as composer package femastudios/enums. PHP 7.3 or greater required.

Introduction

Basic usage

Remember that enums are single-instance, so Greeting::HELLO() === Greeting::HELLO() will always be true.

Main classes

Available methods on enums

Declaring enums

There are multiple ways to declare enums, depending on the level of flexibility required.

Note that your enum classes must always be final and their constructor, if present, must be private.

DocEnum

This is all you have to do in order to declare your enum. The documentation will be automatically parsed and your enums instantiated accordingly.

This is the only implementation that parses the documentation. In all the other examples, this doc is present only to help the IDE, but it can safely be omitted.

ConstEnum

While the previous method is very easy, it doesn't provide a lot of flexibility. Let's say we want to add some parameters to our enum. We can do so like this:

As you can see from the code, it's very easy to pass parameters to the constructor of your enum. In this particular implementation though, you can only pass constant parameters.

To be considered, each const must be private and start with ENUM_: its value must be an array containing the parameters to pass to the constructor.

MethodEnum

Lastly, this implementation allows full control of the creation of your enums.

As you can see, the task of instantiating the enum is completely handed off to the programmer, thus allowing any kind of complex logic.

Similarly to the const implementation, the methods to be considered must be private, static and start with ENUM_.

Your own enum implementation

If you want to implement a custom logic for your enum creation, all you have to do is extend the Enum class and provide a loadAll(string $class) method that returns an array of your enums. Make sure to initialize the name attribute on your instances and to avoid name collisions! The ordinal attribute will be initialized automatically based on the order of the returned array.

Also, keep in mind that the created enums will be kept in a static cache, so the method will only be called once per enum class.


All versions of enums with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-mbstring Version *
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 femastudios/enums contains the following files

Loading the files please wait ....