定制 marcovtwout/yii2-environment 二次开发

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

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

marcovtwout/yii2-environment

Composer 安装命令:

composer require marcovtwout/yii2-environment

包简介

Environment class for Yii 2, used to set configuration for console and web apps depending on the server environment.

README 文档

README

Latest Stable Version Total Downloads Scrutinizer Quality Score

Environment-based configuration class (for example in development, testing, staging and production).

Simple class used to set configuration and debugging depending on environment. Using this you can predefine configurations for use in different environments, like development, testing, staging and production.

The main config (main.php) is extended to include the Yii 2 debug flag. There are mode_<environment>.php files for overriding and extending main.php for specific environments. Additionally, you can overrride the resulting config by using a local.php config, to make changes that will only apply to your specific installation.

This class was designed to have minimal impact on the default Yii generated files. Minimal changes to the index/bootstrap and existing config files are needed.

The Environment is determined with PHP's getenv(), which searches $_SERVER and $_ENV. There are multiple ways to set the environment depending on your preference. Setting the environment variable is trivial on both Windows and Linux, instructions included. You can optionally override the environment on a per-project basis.

If you want to customize this class or its config and modes, extend it! (see ExampleEnvironment.php)

Requirements

Yii 2.*

Installation

Installation via Composer

  1. Add the dependency to your project

    composer require marcovtwout/yii2-environment
    
  2. Modify your index.php (and other bootstrap files)

  3. Modify your main.php config file and add mode specific config files

  4. Set your local environment (see next section)

Setting environment

Here are some examples for setting your environment to DEVELOPMENT.

Windows

  1. Go to: Control Panel > System > Advanced > Environment Variables
  2. Add new SYSTEM variable: name = YII_ENVIRONMENT, value = DEVELOPMENT

Linux/Mac

  1. Open profile files:
  • Global bash shell: /etc/profile
  • Apache (as service): /etc/apache2/envvars
  1. Add the following line: export YII_ENVIRONMENT="DEVELOPMENT"

Apache only (cannot be used for console applications)

  1. Check if mod_env is enabled
  2. Open your httpd.conf or create a .htaccess file
  3. Add the following line: SetEnv YII_ENVIRONMENT DEVELOPMENT

Project only

  1. Create a file mode.php in the config directory of your application.
  2. Set the content of the file to: DEVELOPMENT

Usage

Update bootstrap files

See example-index/index.php

Override environment

You can override the automatic determination of the current environment if needed:

  • Pass the environment to the constructor: new Environment('TEST')
  • For console applications, you can also do: YII_ENVIRONMENT=STAGING ./yii

Structure of config directory

Your protected/config/ directory will look like this:

config/main.php                     (Global configuration)
config/mode_development.php         (Environment-specific configurations)
config/mode_test.php
config/mode_staging.php
config/mode_production.php
config/local.php                    (Optional, local override for mode-specific config. Don't put in your SVN!)

Modify your config/main.php

See example-config/main.php

Optional: in configConsole you can copy settings from configWeb by using value key inherit (see examples folder).

Create mode-specific config files

Create config/mode_<mode>.php files for the different modes. These will override or merge attributes that exist in the main config.

Optional: also create a config/local.php file for local overrides.

Credits and history

Based on the Yii 1 extension: https://github.com/marcovtwout/yii-environment

marcovtwout/yii2-environment 适用场景与选型建议

marcovtwout/yii2-environment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65.87k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 marcovtwout/yii2-environment 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-11-25