定制 mooseware/yaml-config-service-provider 二次开发

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

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

mooseware/yaml-config-service-provider

最新稳定版本:2.0.0

Composer 安装命令:

composer require mooseware/yaml-config-service-provider

包简介

Service provider for Silex for using YAML configuration files

关键字:

README 文档

README

Silex Service provider for YAML configuration files

Installation

Simply add the following line to your composer.json:

"require": {
    ...
    "mooseware/yaml-config-service-provider": "2.*",
    ...
}

Then run composer update at your console.

Usage

Register the provider with your application.

$app->register(new Mooseware\Silex\YamlConfigServiceProvider());

The provider assumes some parameters such as the environment variable name and the config path. By default the variable name (that you may have set through .htaccess) is APP_ENV. The default config file path is </path/to/your/application>/config/. You can override those settings by passing the changes to the providers constructor:

$app->register(new Mooseware\Silex\YamlConfigServiceProvider([
    'envVarName' => 'YOUR_ENV_NAME',
    'configPath' => __DIR__ . '/path/to/your/configfolder',
]));

However, the config file names need to have the following pattern:

config.<env>.yml

Finally, after registering the provider, you can access the configuration attributes through $app['config'].

Example

app/config/config.dev.yml

database:
    host: localhost
    user: myuser
    password: mypassword

web/index.php

<?php
    require_once __DIR__.'/../vendor/autoload.php';

    $app = new Silex\Application();

    $app->register(new Mooseware\Silex\YamlConfigServiceProvider([
        'envVarName' => 'MY_APP_ENV',
        'configPath' => __DIR__ . '/../app/config',
    ]));

    die(var_dump($app['config']));

will show you

array (size=1)
  'database' => 
    array (size=3)
      'host' => string 'localhost' (length=9)
      'user' => string 'myuser' (length=6)
      'password' => string 'mypassword' (length=10)

Any improvements are welcome!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-13