Download the PHP package jomisacu/enumerations without Composer
On this page you can find all versions of the php package jomisacu/enumerations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jomisacu/enumerations
More information about jomisacu/enumerations
Files in jomisacu/enumerations
Package enumerations
Short Description A simple way to handle enumerations in php
License MIT
Informations about the package enumerations
enumerations
A simple class to handle enumerations
why?
In some situations we have to handle groups of static values, enumerations comes to deal with these values in a safe way. Instead of write raw values in your code you can use objects, preventing typo errors and behaviour bugs. It is not about wraps values into constants, not, you can use TypeHint to avoid wrong calls in methods and constructors.
Use cases
Static values: statuses, database enums and options
If you have a currier system you can handle the package states using enumerations: sent, in way, received. Example:
Now, you can handle these values in a safe way.
External values
In some situations we need to handle values that can change by external reasons. Imagine an university that offers multiple college career and by convention they take the decision of apply three code character. Over the time, careers are added, subjects change, etc., etc. So they decide add a prefix to expand the size of code and maintain the same size for all. i.e: Software Engineer could have the code 'XYZ' but after change could be '0XYZ'.
The previous change introduces the problems below:
- Logic broken because the raw values in the code not have mean
- The values in the database are now corrupted because no match with the real values
- No safe way to replace the values in a production system, we need to catch errors by the way
The solutions are the enumerations. See the example...
Enjoy it!