定制 davidepastore/slim-config 二次开发

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

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

davidepastore/slim-config

Composer 安装命令:

composer require davidepastore/slim-config

包简介

A slim middleware to read configuration from different files based on hassankhan/config

README 文档

README

Latest version Build Status Coverage Status Quality Score Total Downloads PSR2 Conformance

A file configuration loader that supports PHP, INI, XML, JSON, and YML files for the Slim Framework. It internally uses hassankhan/config.

Install

Via Composer

$ composer require davidepastore/slim-config

Requires Slim 3.0.0 or newer.

Usage

In most cases you want to register DavidePastore\Slim\Config for a single route, however, as it is middleware, you can also register it for all routes.

Register per route

$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register provider
$container['config'] = function () {
  //Create the configuration
  return new \DavidePastore\Slim\Config\Config('config.json');
};

$app->get('/api/myEndPoint',function ($req, $res, $args) {
    //Here you have your configuration
    $config = $this->config->getConfig();
    $secret = $config->get('security.secret');
})->add($container->get('config'));

$app->run();

Register for all routes

$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register provider
$container['config'] = function () {
  //Create the configuration
  return new \DavidePastore\Slim\Config\Config('config.json');
};

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add($container->get('config'));

$app->get('/foo', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $secret = $config->get('security.secret');
});

$app->post('/bar', function ($req, $res, $args) {
  //Here you have your configuration
  $config = $this->config->getConfig();
  $ttl = $config->get('app.timeout', 3000);
});

$app->run();

Where are the benefits?

The configuration is loaded from the filesystem only when the given route is called in the per route usage. In the other case (all routes) the config should be general and used in the whole routes, because it's read in every request.

Just the tip of the iceberg!

You can read the hassankhan/config documentation here for more info.

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

统计信息

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

GitHub 信息

  • Stars: 33
  • Watchers: 4
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2016-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固