ivoba/dotenv-service-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ivoba/dotenv-service-provider

最新稳定版本:2.0.0

Composer 安装命令:

composer require ivoba/dotenv-service-provider

包简介

A dotenv ServiceProvider for Silex.

README 文档

README

A dotenv ServiceProvider for Silex

Build Status

Caution: this is highly overengineered!

This will set all Env vars that have a given prefix, default is SILEX_, to $app as parameters.
You can pass a function to detect if you want to run dotenv load as well to load vars from an .env file.

The functionality replaces mainly something like this:

$app['env'] = getenv('SILEX_ENV') ? getenv('SILEX_ENV') : 'dev';
if($app['env'] === 'dev'){
    \Dotenv::load();
}
$app['debug'] = getenv('SILEX_DEBUG') ? getenv('SILEX_DEBUG') : false;
$app['this'] = getenv('this') ? getenv('this') : 'that';
//...
\Dotenv::required();

About 10 LOC vs ca. 110 LOC + autoload, yiah
So its actually a bit overdressed for the party, but anyway ;)
Some goodies might be legit as getenv, $_ENV & $_SERVER support.

Usage

Register the Service:

$app->register(new \Ivoba\Silex\EnvProvider(), ['env.options' => ['prefix' => 'MYPREFIX',
    'use_dotenv' => function () use ($app) {
        return $app['env'] === 'dev';
    },
    'dotenv_dir' => __DIR__ . '/../../../..',
    'var_config' => []]
]);
$app['env.load'];

Yo can add default, required, allowed and typecast config options for each var.

$envOptions = ['env.options' => ['var_config' => [
    'hoo' => [EnvProvider::CONFIG_KEY_ALLOWED => 'this'],
    'zack' => [EnvProvider::CONFIG_KEY_REQUIRED => true],
    'dong' => [EnvProvider::CONFIG_KEY_CAST => EnvProvider::CAST_TYPE_BOOLEAN],
    'zip' => [EnvProvider::CONFIG_KEY_DEFAULT => 'zippi']]
]];
$app->register(new \Ivoba\Silex\EnvProvider(), $envOptions);
$app['env.load'];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-26