yatero/enivronment-picker 问题修复 & 功能扩展

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

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

yatero/enivronment-picker

Composer 安装命令:

composer require yatero/enivronment-picker

包简介

Choose a labeled environment based on environment variables or URL.

README 文档

README

This class lets your applications determine which labeled environment is it running in, based on:

  • an environment variable (detected with getenv())
  • a passed URL to the EnvironmentPicker::get() function
  • the current URL (when not run trouh CLI)

Usage

By default, if an environment could not be determined from an environment variable or an URL, the class returns a default label, which is production.

Using host detection

Please note, that when using EnvironmentPicker::get() the getenv() value always gets precedence when both the environment value and labeled regex expressions are present.

$environments = array(
    'local'   => '/^(localhost(:{d}+)?)|(127\.0\.0\.1(:{d}+)?)$/i',
    'staging' => '/^(demo\.my-website\.com)|(8\.8\.8\.8)$/i'
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Returns the label of the environment for the current URL
\Yatero\EnvironmentPicker\EnvironmentPicker::get();


// Return the label of the environment for the given URL
\Yatero\EnvironmentPicker\EnvironmentPicker::get('https://demo.my-website.com/foo/bar');

Using a predefined environment value

You can set the environment variable in your server configurations, in your .htaccess file (if you are using Apache) or on runtime while calling export ENGINE_ENV=staging.

Be careful and initialize the allowed environments beforehand. By default only environments from the list are allowed as values. If you would like to allow ENGINE_ENV to take any value, you should call EnvironmentPicker::strict(false)

$environments = array(
    'local'   => null,
    'staging' => null
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Before getting the current environment make sure that you have the right variable name
\Yatero\EnvironmentPicker\EnvironmentPicker::envVarKey('MY_VAR');

\Yatero\EnvironmentPicker\EnvironmentPicker::get();

You can set labled regex values as a fallback, if the variable is not set or empty.

$environments = array(
    'local'   => '/^(localhost(:{d}+)?)|(127\.0\.0\.1(:{d}+)?)$/i',
    'staging' => '/^(demo\.my-website\.com)|(8\.8\.8\.8)$/i'
);

// Initialize environments
\Yatero\EnvironmentPicker\EnvironmentPicker::init($environments);

// Before getting the current environment make sure that you have the right variable name
\Yatero\EnvironmentPicker\EnvironmentPicker::envVarKey('MY_VAR');

\Yatero\EnvironmentPicker\EnvironmentPicker::get();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固