srdorado/php-dotenv
Composer 安装命令:
composer require srdorado/php-dotenv
包简介
Loads environment variables from .env file to getenv(), $_ENV and $_SERVER
README 文档
README
By srdorado
Base code devcoder-xyz
Loads environment variables from .env file to getenv(), $_ENV and $_SERVER.
Installation
Use Composer
Composer Require
composer require srdorado/php-dotenv
Requirements
- PHP version >= 5.4
How to use ?
APP_ENV=dev
DATABASE_DNS=mysql:host=localhost;dbname=test;
DATABASE_USER="root"
DATABASE_PASSWORD=root
MODULE_ENABLED=true
NUMBER_LITERAL=0
NULL_VALUE=null
Load the variables
<?php use Srdorado\Env\DotEnv; $absolutePathToEnvFile = __DIR__ . '/.env'; (new DotEnv($absolutePathToEnvFile))->load();
Use them!
/** * string(33) "mysql:host=localhost;dbname=test;" */ var_dump(getenv('DATABASE_DNS')); /** * Removes double and single quotes from the variable: * * string(4) "root" */ var_dump(getenv('DATABASE_USER')); /** * Processes booleans as such: * * bool(true) */ var_dump(getenv('MODULE_ENABLED')); /** * Process the numeric value: * * int(0) */ var_dump(getenv('NUMBER_LITERAL')); /** * Check for literal null values: * * NULL */ var_dump(getenv('NULL_VALUE'));
Ideal for small project
Simple and easy!
Processors
Also the variables are parsed according to the configuration passed as parameter to the constructor. The available processors are:
BooleanProcessor
VARIABLE=false will be processed to bool(false)
NOTE: VARIABLE="true" will be processed to string(4) "true"
QuotedProcessor
VARIABLE="anything" will be processed to string(8) "anything"
NullProcessor
VARIABLE=null will be processed to NULL
NumberProcessor
VARIABLE=0 will be processed to int(0)
VARIABLE=0.1 will be processed to float(0.1)
Base code
Due to the need to create a library to manage environment variables through a configuration file that is compatible with php versions >= 5.4, it was decided to use as a base the code published under the MIT license in: https://github.com/devcoder-xyz/php-dotenv
srdorado/php-dotenv 适用场景与选型建议
srdorado/php-dotenv 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「server」 「env」 「load」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 srdorado/php-dotenv 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 srdorado/php-dotenv 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 srdorado/php-dotenv 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
An environment variable convenience library extension for vlucas/phpdotenv
Laravel dotenv manager
Utils to load, parse and work with configuration on Mezzio projects
A jQuery augmented PHP library for creating and validating HTML forms
annotations-scan-plugin
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-12