Download the PHP package freshp/php-enumeration without Composer
On this page you can find all versions of the php package freshp/php-enumeration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download freshp/php-enumeration
More information about freshp/php-enumeration
Files in freshp/php-enumeration
Package php-enumeration
Short Description This small package can represent a enumeration field. For example in a database or an api.
License MIT
Homepage https://github.com/freshp/php-enumeration
Informations about the package php-enumeration
php-enumeration
This small package can represent a enumeration field. For example in a database or an api.
Featureslist:
- inspired and mostly used for MySQL enum-fields or API enum-fields
- it is a simple string representation
- no other values are allow besides the defined in the class
- simple usage and easy to read
- no features a enum do not have to deal with
- with a default fallback value which will be used if no matching value exists in const´s
- you can harden this object by throwing an exception in the
getDefault
-method
- you can harden this object by throwing an exception in the
Install
Basic install via composer
Usage
Take a look in tests/fixtures
to see a executable example.
Create a new object with:
- public const´s which represent strings
- implement the
getDefault
-method
Create an enumeration object
use annotations for better ide support
make the data of the parent toArray
-method public if you need to iterate over all options
Use the enumeration object
-
create the object by static call
-
create the object by normal initialization
-
create a default object (the value from the
getDefault
-method will be called) -
compare the object by using the
__toString
-methodor
Checks
Run each command in the project root directory.
run all check with composer script