Download the PHP package roaresearch/yii2-enum without Composer
On this page you can find all versions of the php package roaresearch/yii2-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download roaresearch/yii2-enum
More information about roaresearch/yii2-enum
Files in roaresearch/yii2-enum
Package yii2-enum
Short Description Enum classes for Yii2 models and forms
License BSD-3-Clause
Homepage http://www.yiiframework.com/
Informations about the package yii2-enum
ROAResearch Yii2 Enum
ROAResearch Yii2 Enum extension provides support for the ussage of enumarions in Yii2 models and forms.
Installation
The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies.
To install, either run
or add
to the require section of your composer.json file.
Usage
Create Enums
This library uses the enum feature added in php8.1, to use them you need to
implement the roaresearch\yii2\enum\DescriptiveEnum interface
By default the DescriptiveEnumTrait defines all the required methods including
automatically trying to translate the case names for the enum to make them human
readable. For example in the case above
Declare Enum for a Model Property
To use the full power of this library its necessary to create models that
implement the roaresearch\yii2\enum\models\EnumMap interface.
The method getStatusDesc() is optional, its useful to easily access the human
readable description of the status.
This way other tools like the validators and widgets can easily interact with the model.
Validator
You can validate an attribute value can be extracted from an enum using the provided validator
More informations for enums
Upgrade from Farystha library
- Models must implement the
EnumMapinterface. - Models have no longer the method
getAttributeDesc(), lost in favor of usingnullsafe operator - Models
enums()method no longer defines the enums themselves but a map for the enum classes. Method signature changed too. - Validator
$skipOnEmptyis set totrue. - Validator will throw exception if the provided model is not an
EnumMapor has no mapped enum for the validated attributes.
License
ROAResearch Yii2 Enum is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.