Download the PHP package vosiz/php-enum without Composer

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

php-enum

Utility to have enum-like classes. We love ENUMS!

Motivation

True enumeration with integers seems to be impossible to achieve in PHP (at least for me), so this is my take on it. Designed to be dynamical - not only for compile time, you can read values from DB f.e. and make dynamic enums. Built on php-utils. Made by personal need, so feel free to use it if it fits yours. MIT - use it however you like.

Requirements

Your own enum

Implement your own enums! Lets say, you have a game and want elemental magic defined other way than with defines or constants. You want to do something like this:

[!IMPORTANT] You can have multiple same values allocated to different keys (some classic enums do not allow it) - here it is permitted. But you can lose consistency if you base on integers (values) too much.

[!IMPORTANT] Keys are unique and they are kept in CamelCase, so dark_air and DarkAir are the same key. Adding a key which is already there throws EnumException.

Usage sample - int-like

Now you can simply use it for example like this. It is value based - integers.

GetValues() gives you a copy, so you can do whatever you want with it and the enum stays as it is.

Usage sample - enum-like

If you need to track or operate with naming of enum (enum key and value in general), you should use something like this:

Dynamic values

Values do not have to be known in Init(). Add them later, from DB f.e. - they land after the preset ones.

A value is an integer, or a string holding one ('4'), anything else throws EnumException.

Useful tips

If you want to distinct 'key' from 'shown key', there is Display property. It is automatically set to key, but you can set it up in custom enum definition. Example.

[!IMPORTANT] You have to still keep first value of array as int (core functionality of enum).

More to look at in samples/.

Tests

Docker is all you need, the suite runs on every supported PHP version.


All versions of php-enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
vosiz/php-utils Version ~1.12.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 vosiz/php-enum contains the following files

Loading the files please wait ...