Download the PHP package knplabs/dictionary-bundle without Composer
On this page you can find all versions of the php package knplabs/dictionary-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download knplabs/dictionary-bundle
More information about knplabs/dictionary-bundle
Files in knplabs/dictionary-bundle
Package dictionary-bundle
Short Description Are you often tired to repeat static choices like gender or civility in your apps ?
License MIT
Informations about the package dictionary-bundle
DictionaryBundle
Are you often tired to repeat static choices like gender or civility in your apps ?
Requirements
- PHP >= 8.1
- Symfony 5.4, 6.4 or 7.*
Installation
Run the following command:
Register the bundle in config/bundles.php
Maintainers
You can ping us if need some reviews/comments/help:
Basic usage
Define dictionaries in your config.yml file:
You will be able to retreive it by injecting the Collection service and accessing the dictionary by its key
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
has 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.
Iterator based dictionary
You can create a dictionary from an iterator:
Iterator based dictionaries are loaded with a lazy strategy. It means that the iterator will not be fetched if you do not use the dictionary.
Combined dictionary
You can combine multiple dictionaries into a single one:
Now you have 3 dictionaries, payment_mode
and extra_payment_mode
contain
their own values but combined_payment_mode
contains all the values of the previous ones.
Extended dictionary
You can create an extended dictionary:
The dictionary world
will now contain its own values in addition
to the europe
values.
Note: You must define the initial dictionary BEFORE the extended one.
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 dictionary
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
Create your own dictionary implementation
Dictionary
Your dictionary implementation must implements the interface Dictionary.
It is automaticaly registered with the autoconfigure: true
DIC feature.
Else you can register it by your self:
Dictionary Factory
You must create a dictionary factory that will be responsible to instanciate your dictionary.
It is automaticaly registered with the autoconfigure: true
DIC feature.
Else you can register it by your self:
Tests
phpspec
php-cs-fixer
phpstan
First install phive.
Then...
rector (optional)
All versions of dictionary-bundle with dependencies
symfony/config Version ^5.4 || ^6.4 || ^7.0@dev
symfony/dependency-injection Version ^5.4 || ^6.4 || ^7.0@dev
symfony/form Version ^5.4 || ^6.4 || ^7.0@dev
symfony/http-foundation Version ^5.4 || ^6.4 || ^7.0@dev
symfony/http-kernel Version ^5.4 || ^6.4 || ^7.0@dev
symfony/validator Version ^5.4 || ^6.4 || ^7.0@dev
twig/twig Version ^2.15.3 || ^3.4.3