Download the PHP package simondeeley/enum without Composer
On this page you can find all versions of the php package simondeeley/enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simondeeley/enum
More information about simondeeley/enum
Files in simondeeley/enum
Package enum
Short Description A simple ENUM object for PHP
License GPL-3.0
Homepage https://github.com/simondeeley
Informations about the package enum
ENUM object for PHP
A simple library for adding ENUM type objects into any existing or new PHP project.
Requirements
- PHP >= 7.1
Installation
composer require simondeeley/enum
Usage
Create a new Enum class using your own chosen enum types
Now you can use your newly designed enum object in your code. Just simply instantiate a new MyAwesomeEnum
every time you want to use an enum. The constants you defined in the class definition determine what the allowed values of the enum object can take. You can add as many constants as you wish, depending on your design needs.
Every time a new instance of your enum object is created, it requires that you pass a value to it's constructor. If the value passed to the constructor is not one of the pre-determined values then an InvalidArgumentException
will be thrown.
Examples
This package provides two enums for out-of-the-box use, Boolean
leverages an enum that is either true or false whilst the second is a list of the days of the week.
Although not mandatory when building enum objects, both Weekday
each provide short-cut static methods to quickly create a new object, for example:
This functionality is built-in to any enums extending the base Enum
type object. The only caveats are that when performing static method calls that it is best to keep in-line with PHP good coding practice and to ensure all constants are typed in uppercase.