定制 tabbi/config-service-provider 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tabbi/config-service-provider

Composer 安装命令:

composer require tabbi/config-service-provider

包简介

A config ServiceProvider for Silex with support for php, json and yaml.

关键字:

README 文档

README

A config ServiceProvider for Silex with support for php, json, yaml, and toml. It is based on Igor Wiedler ConfigServiceProvider. The main diffrence is in usage. It allows now to get config options in "Laravel way". Getting config keys is very simple, first define a folder where you will store all your config files then add all the files into it. The first level of key is file name, next levels depends on you.

Example:

# config/database.php
return = array(
    'db_name' => 'test',
    'db_password' => 'password',
    'db_user' => 'user',
    'db_host' => 'localhost',
);

The getting key will be database.db_name.

Usage

Using Yaml

To use Yaml just pass a file that ends on .yml or .yaml in add method:

$app->register(new Tabbi\Silex\ConfigServiceProvider());
$app['config']->add(__DIR__."/../config/services.yml");
echo $app['config']->get('services.option.value');

Note, it requires ~2.3 - symfony/yaml package.

Using TOML

To use TOML instead of any of the other supported formats, just pass a file that ends on .toml:

$app->register(new Tabbi\Silex\ConfigServiceProvider());
$app['config']->add(__DIR__."/../config/services.toml");
echo $app['config']->get('services.option.value');

Note, it requires ~0.1 - jamesmoss/toml package and you are using a bleeding edge configuration format, as the spec of TOML is still subject to change.

Using plain PHP

Use simple php configs that returns the array of config data, and also make sure it ends with .php:

$app->register(new Tabbi\Silex\ConfigServiceProvider());
$app['config']->add(__DIR__."/../config/services.php");
echo $app['config']->get('services.option.value');

Using Json

To use Json just pass a file that ends on .json in add method:

$app->register(new Tabbi\Silex\ConfigServiceProvider());
$app['config']->add(__DIR__."/../config/services.json");
echo $app['config']->get('services.option.value');

Multiple config files

You can use multiple config files, e. g. one for a whole application and a specific one for a task by calling $app['config]->add() several times.

$app->register(new Tabbi\Silex\ConfigServiceProvider());
$app['config']->add(__DIR__."/../config/services.php");
$app['config']->add(__DIR__."/../config/database.php");
$app['config']->add(__DIR__."/../config/cache.php");
echo $app['config']->get('services.option.value');
echo $app['config']->get('database.option.value');
echo $app['config']->get('cache.option.value');

Register order

Make sure you do not register anything with config name. You don't have to keep correct order just remember to add config before its usage.

统计信息

  • 总下载量: 93
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-11-24