Download the PHP package hello-motto/config-service-provider without Composer
On this page you can find all versions of the php package hello-motto/config-service-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hello-motto/config-service-provider
More information about hello-motto/config-service-provider
Files in hello-motto/config-service-provider
Package config-service-provider
Short Description A service provider to configurate silex ~2.0 with yaml, json and php files
License GPL-3.0+
Informations about the package config-service-provider
ConfigServiceProvider for Silex 2
This is a Service Provider that permits to use YAML, JSON and PHP config files in a Silex app.
Requirements
- silex/silex: 2.X
Suggested
- symfony/yaml: 3.X
Installation
Install with Composer:
$ composer require hello-motto/config-service-provider dev-master
Or add to composer.json
Usage
This Provider will parse your YAML, JSON and PHP files to set config variables.
Those config variables are available through $app['config']['myVariable']
.
Some special variables you can define (parameters variable) also are available through $app['parameters']
.
All the variables that are contained in the several config files are recursively merged in a array.
Add files
You can pass one or several files to the ServiceProvider in the 'config.files' argument. No matter if it's a json, yaml or php file
where PATH_TO_CONFIG_FILE
is location of YML, JSON or PHP file with configuration for example
Files example :
config/config.php
config/config.json
config/config.yml
Add constants
You can also pass to the ServiceProvider constants parameters to replace in your config files. It permits to use the PHP functions within the configuration files. Constants name must begin and end with % character. You can set the constants in the 'config.constants' array :
config/config.json
config/config.yml
The app['config']['ourMotto']
variable will contain In tartiflette we trust
.
Add closures
YAML and JSON files don't allow to use dynamic code. But some Providers like Security Provider are more powerful with closure parameters. That's why it's possible to add some closures with the 'config.closures' parameter. To use the closure parameter, your array must have the same tree structure.
Import files
It's possible to import files from a YAML or JSON config file. You just need to use the object "import" and set an array of resources. The files are always imported with a relative path from the current file. Notice that PHP config files don't support the import method.
config/config_dev.json
config/config_dev.yml
Traits
config() method
Adding this trait to your Application, you can use the config variables as object.
$app['config']
will be available using $app->config()
.
You can also access to the first dimension of the array passing the parameter to the method.
$app['config']['twig']
is available through $app->config('twig')
.
parameters() method
This shortcut also exists for the parameters variables. $app['parameters']['dbhost']
will be the same that $app->parameters('dbhost')
loadFile() method
This shortcut use the ConfigLoader to parse a JSON, YAML or PHP file into an array, replacing the constants that are already set.
loadManyFiles() method
This method does the same as loadFile() with an array of files as argument.