Download the PHP package divengine/enum without Composer

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

Div PHP Enum Solution 1.0.2

This is a PHP Enum Solution using classes and type hinting. Also you can build a taxonomies of enums!

An enumeration type, "enum" for short, is a data type to categorise named values. Enums can be used instead of hard coded strings to represent, for example, the status of a blog post in a structured and typed way.

In July 2019, I wrote a gist searching a solution for this.

https://gist.github.com/rafageist/aef9825b7c935cdeb0c6187a2d363909/revisions

Then I convert the gist in a real project. https://www.phpclasses.org/package/11366-PHP-Implement-enumerated-values-using-classes.html

The problem

Before 8.1, PHP didn't have a native enum type, only a very basic SPL implementation (https://www.php.net/manual/en/class.splenum.php), but this really doesn't cut the mustard. Some solutions using constants, but not resolve the problem. How to validate HOT or COLD ?

From 8.1, PHP have a enums implementation (https://www.php.net/manual/en/language.types.enumerations.php).

And now you can combine this solution with the new features of PHP.

There's a popular package called myclabs/php-enum. It's really awesome, but have a problem because we lose static analysis benefits like auto completion and refactoring.

The solution

Use PHP!

The class divengine\enum help you, but remember: the most important solution is the concept of this library.

With this class, you can solves the following problems:

  1. Constants with different names and equal value can be used as function arguments
  2. Lose static analysis benefits like auto completion and refactoring
  3. Maintaining duplicated code when use docblock type hints to solve the second problem

We need have built-in enums in PHP ! But, for now, this is a solution.

Installation

Composer:

Manual:

Clone the repo:

Include the lib:

Example

First, define your enums. You can build a taxonomy !!!:

Enums.php

Second, use your enums:

Do you like Java programming language?

You actually can switch on enums, but you can't switch on Strings until Java 7. You might consider using polymorphic method dispatch with Java enums rather than an explicit switch. Note that enums are objects in Java, not just symbols for ints like they are in C/C++. You can have a method on an enum type, then instead of writing a switch, just call the method - one line of code: done!

One of the nice things about this approach is that it is simply impossible to get certain types of errors. You can't miss a switch case (you can incorrectly implement a method for a particular constant, but there's nothing that will ever totally prevent that from happening!). There's no switch "default" to worry about. Also, I've seen code that puts enum constants into arrays and then indexes into the arrays - this opens the possibility of array index out of bounds exceptions - just use the enum! Java enums are very, very powerful. Learn all that you can about them to use them effectively.

Also note if you have several enum constants that all have the same behavior for a particular method (like days of the week, in which weekend days have the same behavior and the weekdays Tuesday through Thursday also share the same behavior), you can simply gather that shared code in an enum method that is not overridden by every constant (final protected) and then call that method from the appropriate methods. So, add "final protected void commonMethod() { ... }" and then the implementation of method() in each constant would just call commonMethod().

And.... what about PHP ? This is a similar solution ...

Enjoy!

Documentation: https://divengine.org

--

@rafageist

Eng. Rafa Rodriguez

https://rafageist.com


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version >=5.0.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 divengine/enum contains the following files

Loading the files please wait ....