Download the PHP package biig/dictionary-bundle without Composer
On this page you can find all versions of the php package biig/dictionary-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dictionary-bundle
DictionaryBundle
Are you often tired to repeat static choices like gender or civility in your apps ?
Notice: This bundle is a fork from KnpLabs/DictionaryBundle. We are working on releasing a 3.0 version but for now the released version is 2.x. You should refere to the right branch to have a good documentation.
Requirements
- Symfony >= 3.4
- PHP >= 7.1
Installation
Add the DictionaryBundle to your composer.json
:
Or install it directly with composer command
Register the bundle in app/AppKernel.php
Basic usage
Define dictionaries in your config.yaml file:
You will be able to retrieve it through the dictionary registry service:
Dictionary form type
Now, use them in your forms:
The dictionary form type extends the symfony's choice type and its options.
Validation constraint
You can also use the constraint for validation. The value
have to be set.
Advanced usage
You can specify the indexation mode of each dictionary
Available types
value
(default) : Natural indexationvalue_as_key
: Keys are defined from their valuekey_value
: Define your own keyscallable
: Build a dictionary from a callable
Callable dictionary
You can create a callable dictionary:
Callable dictionaries are loaded with a lazy strategy. It means that the callable will not be called if you do not use the dictionary.
Categories in dictionaries
If you want to retrieve some groups of dictionaries from the registry, then you can specify a category to your dictionary.
Get a registry for this category later:
Transformers
For now, this bundle is only able to resolve your class constants:
You want to add other kinds of transformations for your dictionary values ? Feel free to create your own transformer !
Add your own transformers
Create your class that implements TransformerInterface.
Load your transformer and tag it as knp_dictionary.value_transformer
.
Use your dictionary in twig
You can also use your dictionary in your Twig templates via calling function (or filter)
But you can also access directly to a value by using the same function (or filter)
Faker provider
The KnpDictionaryBundle comes with a faker provider that can be used to provide a random entry from a dictionary.
Alice
To register the provider in nelmio/alice, you can follow the official documentation
or ...
if you use the awesome knplabs/rad-fixtures-load library, the dictionary provider will be automaticaly loaded for you :)
Use dictionary command
You can use the following command to show your app dictionaries easily:
If you want to display only one dictionary, you can set it name in argument
Create your own dictionary implementation
Dictionary
Your dictionary implementation must implements the interface Dictionary. In Symfony >= 3.3, your class will be automatically register as dictionary service.
Dictionary Factory
You must create a dictionary factory that will be responsible to instanciate your dictionary.
All versions of dictionary-bundle with dependencies
symfony/http-kernel Version ~2.8 || ~3.0 || ~4.0
symfony/dependency-injection Version ~2.8 || ~3.0 || ~4.0
symfony/http-foundation Version ~2.8 || ~3.0 || ~4.0
symfony/config Version ~2.8 || ~3.0 || ~4.0
symfony/form Version ~2.8 || ~3.0 || ~4.0
symfony/validator Version ~2.8 || ~3.0 || ~4.0
twig/twig Version ~1.12|~2.0
fzaninotto/faker Version ^1.5