Download the PHP package yokai/enum-bundle without Composer
On this page you can find all versions of the php package yokai/enum-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yokai/enum-bundle
More information about yokai/enum-bundle
Files in yokai/enum-bundle
Package enum-bundle
Short Description Simple enumeration system with Symfony integration
License MIT
Informations about the package enum-bundle
YokaiEnumBundle
This repository aims to provide simple enumeration implementation to Symfony.
Installation
Add the bundle as a dependency with Composer
Enable the bundle in the kernel
Getting started
Let's take an example : our application has some members
and each member has a status
which can be :
new
, labelled as "New"validated
, labelled as "Validated"disabled
, labelled as "Disabled"
Creating the enum
We first need to create the class that will handle our enum :
That's it, the bundle now knows your enum.
note : every enum has a name. That name is the enum identifier across your application. You can use any string for that purpose, as long it is unique. Using the enum class here is a very common way to do.
Configuring validation
We will now be able to configure Member
's model validation :
Setting up the form
Now that validation is configured, the only thing we have to do is to add a field on our form :
Rendering enum label
Display label of any enum value within a Twig template :
Translating your enum
Now, maybe you will need to display the enum label in different locales.
We got you covered here with a dedicated base class for your translated enums :
Now you can create the translation keys in your catalog :
note : the translation key format is generated using the
$transPattern
constructor argument, which must be valid a sprintf pattern (containing one%s
)
More examples
See examples from tests.
See example Symfony project in integration test suite.
Recipes
- Creating enums
- Creating translated enums
- Integration with PHP native enum
- Integration with myclabs/php-enum
- Migrating from standard Symfony
- Integration with SonataAdminBundle
MIT License
License can be found here.
Authors
The bundle was originally created by Yann Eugoné. See the list of contributors.
Thank's to PrestaConcept for supporting this bundle.