helhum/dotenv-connector 问题修复 & 功能扩展

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

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

helhum/dotenv-connector

Composer 安装命令:

composer require helhum/dotenv-connector

包简介

Makes it possible to set environment variables for composer projects.

README 文档

README

This is a composer plugin, that makes environment variables from a .env file available for any composer based project, without the need to modify code in the project.

Background info

You may want to read why it is a good idea to store config in the environment. The idea of dotenv is to make this as easy as possible and this is why the phpdotenv library was created. phpdotenv loads environment variables from an .env file to getenv(), $_ENV and $_SERVER, but you need to add the parsing code for that yourself.

composer + symfony/dotenv + dotenv connector = <3

The idea of this library is, that every composer managed project, a .env file (in the same location as your root composer.json) is automatically parsed and loaded, at composer autoload initialisation time. This means that the environment variables are available very early, so that you can use it also during boot time of your application.

If the environment variable APP_ENV is set to any value, or the specified .env file does not exist, no operation is performed, so that you can safely require this package for production.

If you have the possibility to expose environment variables in a production environment, it is recommended to do so and also set APP_ENV and use the variables that are directly exposed in the environment.

However for smaller scale projects it is still a valid and easy solution to use a .env file also for production environments.

You can set the environment variable DOTENV_CONNECTOR_OVERRIDE to enable overriding of existing environment variables with the values of the .env file.

configuration options

Usually you don't need any configuration options. However if you need to, you can adapt the path or name of the .env to fit your requirements.

You configure dotenv connector in the extra section of the root composer.json file like that:

  "extra": {
      "helhum/dotenv-connector": {
          "env-file": ".env",
          "adapter": "Helhum\\DotEnvConnector\\Adapter\\SymfonyDotEnv"
      }
    }

env-file

You can specify a relative path from the base directory, if you want to put your .env file a different location.

The default value is ".env", which means next to your root composer.json.

Side note for quoting values in the .env file

As the .env file parsing behaves like if it was included in a shell, you have to be aware of that values with literal $ signs need to be enclosed in single quotes. This may be the case if you use hashed values of credentials you pass via .env, for example.

adapter

You can specify a class that implements \Helhum\DotEnvConnector\DotEnvVars interface, if you need a different way to expose env vars.

The default value is "Helhum\DotEnvConnector\Adapter\SymfonyDotEnv", which uses symfony/dotenv default parsing of the one .env file.

This could be useful though e.g. if you prefer to use another dotenv parsing library to expose the variables defined in .env or you want to switch to another parsing strategy of the Symfony dotenv parsing. In the latter case use "Helhum\DotEnvConnector\Adapter\SymfonyLoadEnv" as value for this option. Have a look at the existing implementations for examples.

Feedback

Any feedback is appreciated. Please write bug reports, feature request, create pull requests, or just drop me a "thank you" via Twitter or spread the word.

Thank you!

helhum/dotenv-connector 适用场景与选型建议

helhum/dotenv-connector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.92M 次下载、GitHub Stars 达 159, 最近一次更新时间为 2016 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 helhum/dotenv-connector 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 4.92M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 163
  • 点击次数: 23
  • 依赖项目数: 42
  • 推荐数: 7

GitHub 信息

  • Stars: 159
  • Watchers: 6
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-18