承接 formigone/php-config 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

formigone/php-config

Composer 安装命令:

composer require formigone/php-config

包简介

README 文档

README

This project is a loose port of node-config. I've only implemented enough of it to help me get going with an existing project.

What does it do?

The goal of this package is to help you manage configuration files separated by environment, but used as a single object.

How it works

Suppose your application exists in three environments: development, stage, and production. Each environment has its own unique configurations, and all three share some configuration in common.

As an organized developer, you'll create a config directory somewhere in your project, where you'll store the following files:

/project
  /config
     default.json
     development.json
     stage.json
     production.json

// config/default.json
{
  "appVersion": "1.0.0",
  "app": {
    "views": {
      "cache": false
    }
  }
}

// config/development.json
{
  "db": {
    "username": "root",
    "password": "",
    "host": "localhost"
  }
}

// config/default.json
{
  "db": {
    "username": "stage-user",
    "password": "stage-password",
    "host": "stage-db"
  }
}

// config/default.json
{
  "db": {
    "username": "secure-user",
    "password": "secure-password",
    "host": "super-cluster"
  },
  "app": {
    "views": {
      "cache": true
    }
  }
}

You'll then have a single config object for whatever environment you're in, where default.json and the environment-specific .json object are merged together, with the default values being overwritten by the environment values (using a shallow merge).

$env = getenv('APP_ENV');
$configPath = __DIR__ . '/config';

$config = new Formigone\Config($env, $configPath);

$appVersion = $config->get('appVersion');
$db = $config->get('db');
$shouldCacheViews = $config->get('app.views.cache');

Why reinvent the wheel?

So this project essentially mimics ZF1's Zend_Config, which allows for inheritable configs. Why use this instead?

  • Why use JSON?
    • So configs can be shared across PHP and JavaScript/Node.js
  • Why not use Zend_Config_Json?
    • Because Zend_Config_Json only parses a single file. That works fine in PHP, but if you use something in Node.js like node-config (which is what I happen to use), the you can't reuse the same config files. Given my specific use case (where I'm reusing configs and starting off with node-config), this makes sense, and hence my need for this package.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-10-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固