Download the PHP package davidianbonner/enumerated without Composer
On this page you can find all versions of the php package davidianbonner/enumerated. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davidianbonner/enumerated
More information about davidianbonner/enumerated
Files in davidianbonner/enumerated
Package enumerated
Short Description Enums represent a set of predefined values. Useful for ensuring data consistency.
License MIT
Homepage https://github.com/davidianbonner/enumerated
Informations about the package enumerated
Enumerated
An enumerated type (Enum) is a data type that consists of a set of predefined values. This can be useful for ensuring data consistency. The Enumerated package provides a simple base class for creating enumerated types allowing the devloper to define values statically.
Install
Via Composer
Usage
Most applications require some form of an enumerated type. PHP does not have native Enum support (yet: https://wiki.php.net/rfc/enum). To get past this, we tend to pack groups of predefined values into config or settings files as arrays. This doesn't represent the data or it's type in a straightforward manner.
Before
Used like so:
After
An enum would be a better fit for this set of values.
Used like so:
Validate a value
A value can be validated against the predefined values:
Laravel Collection instance
This package requires the Laravel Support package in order to return a collection of the available values:
Return keys
The allValues
and collect
method will accept a boolean argument to return the keys/constant names:
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.