Download the PHP package modera/config-bundle without Composer
On this page you can find all versions of the php package modera/config-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download modera/config-bundle
More information about modera/config-bundle
Files in modera/config-bundle
Package config-bundle
Short Description Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.
License MIT
Informations about the package config-bundle
ModeraConfigBundle
Bundles provides tools that allow to you to dynamically store and fetch your configuration properties in a flexible way.
You can store any type of configuration property - your configuration property can store both simple values (like string,
integers, arrays) or complex ones - like objects or references to entities, this is achieved by using so called
"Handlers" (implementations of \Modera\ConfigBundle\Config\HandlerInterface
).
Installation
Step 1: Download the Bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
This bundle should be automatically enabled by Flex.
In case you don't use Flex, you'll need to manually enable the bundle by
adding the following line in the config/bundles.php
file of your project:
Publishing configuration properties
Before you can use your configuration properties you need to publish them. Publishing process consists of several steps:
- Create a provider class.
- Register your provides class in service container with "modera_config.config_entries_provider" tag.
- Use
modera:config:install-config-entries
command to publish exposed configuration entries.
This is how a simple provider class could look like:
Once you have a class you need to register it in a service container:
Now we can use modera:config:install-config-entries
to publish our configuration property.
Fetching configuration properties
In order to fetch a configuration property in your application code you need to use
modera_config.configuration_entries_manager
service.
Twig integration
The bundle also provides integration with Twig that allow you to fetch configuration properties' values from your
template. For this you will want to use modera_config_value
function:
This will print value for "my_property_name" configuration property. By default if no given configuration property is found then exception is thrown but you can change this behaviour by passing FALSE as second argument to the function and in this case NULL be returned instead of throwing an exception.
As you will read later in this document the bundle also has support for associating configuration entries with users. To
fetch a user specific configuration property from a template use modera_config_owner_value
, for example:
Handlers
By default the bundle is capable of storing these types of values:
- string
- text
- float
- array
- boolean
- references to entities
If you need to store some more complex values then you need to implement \Modera\ConfigBundle\Config\HandlerInterface
interface. Please see already shipped implementations (\Modera\ConfigBundle\Config\EntityRepositoryHandler
,
for example) to see how you can create your own handlers.
Creating user related configuration entries
Sometimes you may want to store configuration entries which are not related to the system as a whole but instead
to one single user, for example - user's preferred admin panel language. To achieve this you need to use
modera_config/owner_entity
semantic configuration key to specify a fully qualified name of user entity. For example:
Once owner_entity
is configured don't forget to update your database schema by running doctrine:schema:update --force
.
Now that we have proper configuration in place and database schema has been updated when creating new configuration entries you can specify "owner", for example:
Hints
In your application code when working with components from ModeraConfigBundle you should rely on interfaces instead of
implementations, that is, when you use modera_config.configuration_entries_manager
rely on
\Modera\ConfigBundle\Manager\ConfigurationEntriesManagerInterface and when working with configuration entries rely on
\Modera\ConfigBundle\Manager\ConfigurationEntryInterface this way you will make your code portable. By default the bundle
uses Doctrine ORM to store values for configuration entries but later some more storage mechanism may be added and if you
rely on interfaces then you won't need to update your code to leverage new possible storage engines.
Licensing
This bundle is under the MIT license. See the complete license in the bundle: Resources/meta/LICENSE
All versions of config-bundle with dependencies
twig/twig Version ~1.34|~2.4
doctrine/orm Version ^2.5
doctrine/doctrine-bundle Version ^1.6|^2.0
symfony/framework-bundle Version ^3.4|^4.0
modera/foundation-bundle Version ~3.1|~4.0
sergeil/expander-bundle Version ^1.0