承接 josegonzalez/cakephp-environments 相关项目开发

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

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

josegonzalez/cakephp-environments

Composer 安装命令:

composer require josegonzalez/cakephp-environments

包简介

CakePHP plugin to handle environments-level configuration

README 文档

README

Build Status Coverage Status Total Downloads Latest Stable Version Documentation Status Gratipay

Environments Plugin

A plugin to handle environment-level configuration

Requirements

  • CakePHP 3.x

Installation

[Using Composer]

View on Packagist, and copy the json snippet for the latest version into your project's composer.json. Eg, v. 1.0.0 would look like this:

{
	"require": {
		"josegonzalez/cakephp-environments": "3.0.0"
	}
}

Enable plugin

You need to enable the plugin your config/bootstrap.php file:

Plugin::load('Josegonzalez/Environments');

If you are already using Plugin::loadAll(); before usage, then this is not necessary.

Usage

Setup a directory structure as follows:

config/environments.php
config/environments/production.php
config/environments/staging.php
config/environments/development.php

We specify multiple environment files to separate the various configurations and make it easy to inspect a given environment. This is not necessary, but useful if you are configuring a large amount of information.

Your environments.php should contain the following:

<?php
use Josegonzalez\Environments\Environment;

include dirname(__FILE__) . DS . 'environments' . DS . 'production.php';
include dirname(__FILE__) . DS . 'environments' . DS . 'staging.php';
include dirname(__FILE__) . DS . 'environments' . DS . 'development.php';

Environment::start();
?>

Then, you need to include the environments.php file you created in your application, for example in bootstrap.php:

include dirname(__FILE__) . DS . 'environments.php';

This will:

  • Load the environments plugin in cases where it may not already be loaded
  • Include every environment, in order of specificity (development is usually last)
  • Start the environment

Environment Configuration

Each environment may be configured as follows:

Josegonzalez\Environments\Environment::configure($name, $params, $config = null, $callable = null);

Example usage of the \Josegonzalez\Environments\Environment::configure() call is available in the config/environments folder of this plugin.

  • $name: Usually something like production or development. Good practice is to name it the same as the file it was in, so that there isn't any confusion as to what a given env file contains

  • $params: An array or boolean of environment variables used to check whether this environment applies. If a boolean and set to true, this environment is automatically initiated. A value of true should only be used for development:

    If a previous environment is not enabled, this one will be set

    \Josegonzalez\Environments\Environment::configure(
        'development',
        true,
        ['debug' => true]
    );

    If an array, the keys may be function names that are called, with the values being passed to it:

    \Josegonzalez\Environments\Environment::configure(
        'development',
        [
        	'some_function' => 'aValueForThisCheck',
        	'another_function' => 'aDifferentValueForThisCheck',
    	]
    );

    In all other cases, we simply check the environment:

    \Josegonzalez\Environments\Environment::configure(
        'octo_development',
        [
        	'SERVER_NAME' => 'octo-example.dev',
        ]
    );
    
    \Josegonzalez\Environments\Environment::configure(
        'bear_development',
        [
        	'SERVER_NAME' => 'bear-example.dev',
        ]
    );
    
    \Josegonzalez\Environments\Environment::configure(
        'development',
        [
    		'CAKE_ENV' => 'development',
    	]
    );

    If we are running in CLI, the only check enforced is CAKE_ENV, and the value MUST be the name of the environment:

    CAKE_ENV=production Console/cake bake all

    If the CAKE_ENV environment variable is set at all, it takes precedence over everything, including a boolean value for $params.

  • $config: If set, an array of keys => values that are set via Configure::write(). Useful for batch-setting api keys, database connection information, etc.

  • $callable: A PHP callable, such as ['ClassName', 'functionName']. It is also possible to use an anonymous function. This is the preferred method of setting information that might depend upon the value of some function call.

License

Copyright (c) 2014 Jose Diaz-Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

josegonzalez/cakephp-environments 适用场景与选型建议

josegonzalez/cakephp-environments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91.51k 次下载、GitHub Stars 达 46, 最近一次更新时间为 2014 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「configuration」 「cakephp」 「environments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 josegonzalez/cakephp-environments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 josegonzalez/cakephp-environments 我们能提供哪些服务?
定制开发 / 二次开发

基于 josegonzalez/cakephp-environments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 46
  • Watchers: 10
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-13