davigs / silex-yaml-config-service-provider
Silex ServiceProvider 用于使用 YAML 配置文件
该软件包的官方仓库似乎已消失,因此软件包已被冻结。
1.0.5
2017-09-28 18:40 UTC
Requires
- silex/silex: ^2.2
- symfony/yaml: ^3.3
This package is not auto-updated.
Last update: 2019-01-30 01:10:20 UTC
README
Silex 的 ServiceProvider,用于使用 YAML 配置文件。
安装
要使用它,请将以下行添加到您的 composer.json 中
"require": {
...
"davigs/silex-yaml-config-service-provider": "1.*"
...
}
使用方法
在您的初始 Silex 文件(index.php 或其他)的某个位置包含以下代码行
$app->register(new Davigs\Silex\YamlConfigServiceProvider(PATH_TO_CONFIG));
现在您可以通过 $app['config']
访问所有配置变量。
示例
config.yml
database:
host: localhost
user: myuser
password: mypassword
index.php
<?php
require_once __DIR__.'/../vendor/autoload.php';
$app = new Silex\Application();
// Considering the config.yml files is in the same directory as index.php
$app->register(new Davigs\Silex\YamlConfigServiceProvider('config.yml'));
echo $app['config']['database']['host'];
...