Download the PHP package iqomp/enum without Composer
On this page you can find all versions of the php package iqomp/enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package enum
iqomp/enum
Static data enum provider. This module provide list of enums that may used by application.
Installation
Publishing Config
Configuration
To add new enum data or modify exists one, modify file on
/config/autoload/enum.php to return data as below:
Or if you prefer to use file ConfigProvider.php, add data as below:
Make sure to update your composer.json file to let hyperf identify the config file:
Translation
If you want the enum label to be translated, make sure to install module
hyperf/translation. Add new translation
on folder storage/languages/vendor/enum/{locale}/{enum-name}.php.
Usage
Use class Iqomp\Enum\Enum to create enum object with specified value.
Method
List of method defined by this class object:
__construct(string $name, $value=null, string $type=null): Enum
Create new Enum object. This method accept parameters:
name::stringThe name of enum datalist.value::int|strThe value of enum item.type::stringConvert provided value asintorstr.
__get($name): mixed
Get enum data property, accepted name are value, label, and options.
__toString(): string
Return string enum label.
jsonSerialize()
Convert the enum to json_encode ready parameter.
Form Validator
If you're using validator iqomp/validator
for your object or form validator, this module add new form validator rule named
enum to validate if user provided data is in registered enum.
enum => name
Make sure user provided value is in registered enum, the value of user posted data can be single int/str or array of it.
Linter
Run below script to run psr-12 linter:
Formatter
If you're using formatter iqomp/formatter
for your object formatter, this module add new object format type named enum
and multiple-enum that can be use to convert object property value to enum
object.
enum
Convert current object property value to Iqomp\Enum\Enum object.
multiple-enum
Convert current object property value to array of Iqomp\Enum\Enum with custom
separator:
If property separator is not set, PHP_EOL will be used. It also accept
separator 'json' that will use json_decode for separation. If the value of
object property is already array, no separation/explode will used.