68publishers/environment 问题修复 & 功能扩展

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

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

68publishers/environment

Composer 安装命令:

composer require 68publishers/environment

包简介

Composer plugin for environment loading.

README 文档

README

The component based on the symfony/dotenv for simple loading of the ENV variables and detecting a debug mode.

Checks Coverage Status Total Downloads Latest Version PHP Version

Installation

$ composer require 68publishers/environment

Usage

Default ENV variables

The default ENV variables are:

  • APP_ENV
  • APP_DEBUG

Both variables will be always accessible in the global arrays $_ENV and $_SERVER. The default value for APP_ENV is dev and 0 for APP_DEBUG.

ENV variables loading

For ENV variables loading call this static method after requiring Composer's autoload and before your application is stared. The first argument is a relative path to the application root directory and the second argument is an array of debug mode detectors.

<?php

use SixtyEightPublishers\Environment\Debug;
use SixtyEightPublishers\Environment\Bootstrap\EnvBootstrap;

require __DIR__ . '/../vendor/autoload.php';

EnvBootstrap::boot([
    new Debug\CliOptionDetector('debug_please'), // the debug mode is enabled if an option "--debug_please" is defined (CLI only)
    new Debug\IpAddressDetector([
        '185.141.252.240', // the debug mode is enabled always for this IP address
        'john_dee@135.151.252.240', // the debug mode is enabled for this IP address and a cookie called "debug_please" must exist with value "john_dee"
    ], 'debug_please'),
    new Debug\SimpleCookieDetector('ineeddebug123', 'debug_please'), // the debug mode is enabled if a cookie called "debug_please" exists and has the value "ineeddebug123"
    new Debug\EnvDetector(), // the detection is performed from loaded ENV variables, the debug mode is enabled if a variable "APP_DEBUG=1" is defined or if a variable "APP_ENV" has a different value than, "prod"
]);

// All your ENV variables are now accessible in the global arrays `$_ENV` and `$_SERVER`

If you're using Nette Framework then you can use this method in the application bootstrap instead:

<?php

use Nette\Bootstrap\Configurator;
use SixtyEightPublishers\Environment\Bootstrap\EnvBootstrap;

require __DIR__ . '/../vendor/autoload.php';

$configurator = new Configurator();

EnvBootstrap::bootNetteConfigurator($configurator, [
	// define detectors here
]);

// All your ENV variables are now accessible in the global arrays `$_ENV` and `$_SERVER`
// The debug mode on the configurator is set by the ENV variable `APP_DEBUG`
// The ENV variables are accessible in DI container and Neon configuration as dynamic parameters with prefix `env.` e.g. `%env.APP_ENV%`

ENV variables caching/dumping

All ENV variables are always (in each request) parsed from .env files by default. This is a good solution for developers because all changes are immediately applied after the change. But sometimes (mainly on the production) you don't want to parse .env files in each request. If you want to cache the ENV variables then run following Composer command:

$ composer dotenv:dump <APP_ENV>

or shorter

$ composer dump-env <APP_ENV>

The file .env.local.php will be created in the application's root directory, and it will be used instead of all your .env files.

Nette DI Extension

The package includes the Compiler Extension to Nette DI. Its registration is not necessary for variables loading to work, but it adds two console commands to the application.

extensions:
	environment: SixtyEightPublishers\Environment\Bridge\Nette\DI\EnvironmentExtension

Command dotenv:dump

The command works just like the composer command. The env argument is optional here, the current APP_ENV of the application is used as the default value.

$ bin/console dotenv:dump [<env>] [--empty]

Command debug:dotenv

The command lists all dotenv files with variables and values.

$ bin/console debug:dotenv

Contributing

Before opening a pull request, please check your changes using the following commands

$ make init # to pull and start all docker images

$ make cs.check
$ make stan
$ make tests.all

68publishers/environment 适用场景与选型建议

68publishers/environment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.79k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-06