-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Aleksandr Ivanov edited this page Jan 21, 2021
·
5 revisions
# config/app.yml
debug: true
database:
driver: pdo_mysql
host: localhost
$app = new \Silex\Application(['debug' => false]);
$app->register(new Misantron\Silex\Provider\ConfigServiceProvider(
[__DIR__ . '/config/app.yml']
));
var_dump(
$app['debug'], // true
$app['database'] // ['driver' => 'pdo_mysql', 'host' => 'localhost']
);
# config/base.yml
debug: true
database:
driver: pdo_sqlite
host: file::memory:
port:
# config/prod.yml
debug: false
database:
driver: pdo_mysql
host: db.instance.host
port: 3305
$app = new \Silex\Application();
$app->register(new Misantron\Silex\Provider\ConfigServiceProvider(
[
__DIR__ . '/config/base.yml',
__DIR__ . '/config/prod.yml',
]
));
var_dump(
$app['debug'], // false
$app['database'] // ['driver' => 'pdo_mysql', 'host' => 'db.instance.host', 'port' => 3305]
);
Each string surrounded by %
symbol will be replaced by values from replacement dictionary.
// config/app.php
return [
'debug' => true,
'cert.root' => '%cert_root%',
];
$app = new \Silex\Application();
$app->register(new Misantron\Silex\Provider\ConfigServiceProvider(
[__DIR__ . '/config/app.json'],
[
'cert_root' => '/opt/cert', // value for replacement
]
));
var_dump(
$app['debug'], // true
$app['cert.root'] // '/opt/cert'
);
# .env
APP_DEBUG=false
# config/app.yml
debug: '%env(bool:APP_DEBUG)%'
$app = new \Silex\Application(['debug' => true]);
$app->register(new Misantron\Silex\Provider\ConfigServiceProvider(
[__DIR__ . '/config/app.yml']
));
var_dump($app['debug']); // false