climbx/config 问题修复 & 功能扩展

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

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

climbx/config

Composer 安装命令:

composer require climbx/config

包简介

Tools to manage framework config files. Implements PSR-11

README 文档

README

Framework config. files manager. Implements PSR-11

Configuration files formats

This component accepts Yaml and Json files formats.

Full Example

With JsonLoader

// myConfig.json

{
  "FOO": "BAR"
}
// PHP Code

use Climbx\Bag\Bag;
use Climbx\Config\Loader\JsonLoader;
use Climbx\Filesystem\FileHelper;
use Climbx\Config\Parser\EnvVarParser;
use Climbx\Config\Reader\Reader;
use Climbx\Config\ConfigContainer;

// Bag with array of .env data

// JsonLoader
$jsonLoader = new JsonLoader(__DIR__ . 'config/', new FileHelper());

// Config files Reader
$env = new Bag(['FOO' => 'BAR']); // loaded from .env file
$reader = new Reader($jsonLoader, new EnvVarParser($env));

// Container
$container = new ConfigContainer($reader);

/*
 * get() method
 * 
 * If the config file exists it will be returned
 * 
 * If not, a NotFoundException is thrown.
 * 
 * If the config file is not valid, a ConfigurationParserException
 * is thrown
 * 
 * If a referenced .env var is missing in .env file,
 * a EnvParameterNotFoundException is thrown.
 */
$config = $container->get('myConfigId');

/*
 * has() method.
 * 
 * This method returns true if the config exists and is readable,
 * and false otherwise.
 */
$config = $container->has('myConfigId');

Env Vars Parser

It is possible to add a reference to a .env var into a configuration var. It is done with the magic expression $env(MY_ENV_VAR). If the reference exists in .env, it will be replaced by its value. If not, a EnvParameterNotFoundException will be thrown.

# .env file

FOO=BAR
# config.yaml

BAZ: $env(FOO)
// PHP Code

$container = new ConfigContainer($reader);

$config = $container->get('config');
echo $config->get('BAZ'); // Will print: BAR

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固