定制 srdorado/php-dotenv 二次开发

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

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

srdorado/php-dotenv

最新稳定版本:1.0.0

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.

License Packagist PHP Version Support Packagist Version Packagist Downloads Composer dependencies Test workflow Codecov composer.lock

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固