Download the PHP package zlikavac32/php-enum-symfony without Composer
On this page you can find all versions of the php package zlikavac32/php-enum-symfony. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zlikavac32/php-enum-symfony
More information about zlikavac32/php-enum-symfony
Files in zlikavac32/php-enum-symfony
Informations about the package php-enum-symfony
PHP Enum Symfony
Symfony support for zlikavac32/php-enum.
Table of contents
- Installation
- Usage
- Form
- Validator
- Limitations
Installation
Recommended installation is through Composer.
Usage
Assumption is that there exists a valid enum \YesNoEnum
.
Form
Form type for enum is provided as \Zlikavac32\SymfonyEnum\Form\Type\EnumType
. There is one required options enum_class
which must contain enum class FQN.
Internally this extends \Symfony\Component\Form\Extension\Core\Type\ChoiceType and populates choices from the defining enum_class
.
If any of the choices
and/or choice_loader
options is/are passed, an \LogicException
will be thrown. Since these fields are overridden internally, passing them from the outside could cloud code's original purpose. Any other option provided by the \Symfony\Component\Form\Extension\Core\Type\ChoiceType
can be used.
Validator
Two constraints are provided, \Zlikavac32\SymfonyEnum\Validator\Constraints\ValidEnumElement
and \Zlikavac32\SymfonyEnum\Validator\Constraints\ValidEnumElementName
. Internally, they use \Symfony\Component\Validator\Constraints\Choice
.
Required constraint argument is enumClass
which must contain enum class FQN.
If any of the choices
, callback
and/or strict
options is/are passed, an \LogicException
will be thrown. Since these fields are overridden internally, passing them from the outside could cloud code's original purpose. Any other option provided by the \Symfony\Component\Validator\Constraints\Choice
can be used.
ValidEnumElement
- accepted values arenull
and any valid enum element from the defined enum class FQNValidEnumElementName
- accepted values arenull
and any valid enum element name from the defined enum class FQN
Example for annotation use:
Limitations
Due to doctrine/common issue #794 with checks for aliased namespaces, validation of form enum element within an array will throw exception in following cases:
- on
Windows
validation does not work at all (due to the anonymous classes) - on
Linux
- short enum definition (one that useseval()
) does not work so the workaround is to manually instantiate elements - on
OSX
- have to check but I'd assume same asLinux
For more details on what's wrong and why, feel free to check related issue.
All versions of php-enum-symfony with dependencies
zlikavac32/php-enum Version ^3.0
symfony/form Version ^4.4
symfony/options-resolver Version ^4.4
symfony/validator Version ^4.4