Download the PHP package ojezu/dynamic-parameter-bundle without Composer
On this page you can find all versions of the php package ojezu/dynamic-parameter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ojezu/dynamic-parameter-bundle
More information about ojezu/dynamic-parameter-bundle
Files in ojezu/dynamic-parameter-bundle
Package dynamic-parameter-bundle
Short Description Symfony3.4 bundle that facilitates dynamic parameter loading at start of each request
License MIT
Informations about the package dynamic-parameter-bundle
OJezu/DynamicParameterBundle
This bundle enables having multiple configurations (installations) in one Symfony application. It does so, by supplying two independent features:
- Installation-aware kernel, and installation-dependent parameters
- Advanced parameter provider, that can read parameters from any source.
Combination of this features enable implementing multi-tenant applications, configured to use different resources separated at infrastructure level for each tenant. The resources can be database connection, filesystem adapters, etc. Moreover, configuration storage can be off-loaded to a database server, JSON file, zookeeper instance, with a custom or build-in parameter provider service, which will load appropriate configuration based on installation selected in application kernel.
Requirements
This bundle requires Symfony 3.4, as it depends on advanced environment variable processing.
Usage
Note: Processors from this bundle do not read actual environment variables.
Multi-installation
Provide kernel with information about installation (see configuration below), and then in your configuration you can use that information as parameters.
Usage is similar to plain environment variables, but gives more control, as it's developer who decides what and from
where will find its way into Installation
object. Installation parameters can be set based on request headers, php-cli
arguments and any other data source, as implemented in application using this bundle (see configuration below).
All Installation
class instance public properties can be accessed, and Installation class can be extended,
with properties you need.
Advanced parameter provider
After configuring advanced parameter provider (see below), you are able to map parameters to abstract configuration
paths used to obtain parameter values from any source, as long as there is a provider for that source. Providers are
very simple services, that just have to implement ParameterProviderInterface
. JSON local and remote file provider is
already provided by this bundle, more powerful than Symfony built-in "json:" env variable processor.
This configuration will find database.host value in JSON config file, and provide it to DBAL configuration.
Using them together
While both features offer more than what's built in Symfony 3.4, using them together allows for easy management of multiple configurations supported by same Symfony application.
Configuration
Multi-installation
In order to be able to use multi-installation support:
-
Enable it in configuration:
-
Change your AppKernel to extend
\OJezu\DynamicParameterBundle\Kernel\Kernel
-
Make sure that in all places where kernel is created in your application, it is provided with
Installation
instance. Kernel is usually created byweb/*.php
orpublic/*.php
files, but remember to modify yourbin/console
too.Complete examples can be found in
doc/examples
directory of this repository. - In
bin/console
be sure to also swapApplication
with one provided by this bundle, if you want to specify installation via CLI option - otherwise parsing of argv may introduce problems.
Complete examples can be found in doc/examples
directory
Advanced parameter provider
You must provide mapping for supported parameters. It is required due to limitations in %env(processor:variable)%
Symfony DI Container configuration syntax, and to allow paths that can be easily adapted to any configuration provider.
Those parameters can later be used in all places in your application configuration, no matter support from configured bundle:
Using other parameters
In paths all previously loaded parameters can be used, including ojezu_installation
parameters.
Parameter providers
Built-in parameter providers
LocalJsonFileParameterProvider
Opens and parses json file from local disk.
RemoteJsonFileParameterProvider
Downloads json file with GuzzleHttp client and optionally caches it in a PSR-16 Simple Cache compatible cache.
Custom parameter providers
You can use any service implementing OJezu\DynamicParameterBundle\Service\ParameterProviderInterface
interface.
Keep in mind that your provider is a service - it can have its arguments injected, it can be tagged etc. As long as
there is no cycle it will work like any other service (no use trying to inject ojezu_param
s there!)
Defaults?
Yes.
No config mode
In some instances there is no configuration to be loaded - e.g. when warming cache. For those instances there is "no config mode", in which provider won't be used, and all variables will be resolved to null, unless given explicit value for use in those scenarios. Defaults won't be used.
Enable it by using load_configuration
option in processor section:
Extending this bundle in your application
Points for expansion are
Installation
value object for ojezu_installation- Parameter providers
If you need more options from Installation
, extend that class with additional public properties or methods,
and use your extended class in place of the base Installation.
New providers can be written by extending OJezu\DynamicParameterBundle\Service\ParameterProviderInterface
and
configured as described in Configuration part of this ReadMe
Testing
would be nice.
License
MIT
All versions of dynamic-parameter-bundle with dependencies
symfony/config Version ^3.4
symfony/http-kernel Version ^3.4
symfony/expression-language Version ^3.3
psr/simple-cache Version ^1.0
guzzlehttp/guzzle Version ^6.3