承接 darlanschmeller/php-env-loader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

darlanschmeller/php-env-loader

最新稳定版本:v2.0.2

Composer 安装命令:

composer require darlanschmeller/php-env-loader

包简介

Lightweight .env file loader for PHP with automatic type casting

README 文档

README

PHP Packagist License PHP Composer CI

A lightweight, object-oriented PHP library to load .env files into $_ENV with automatic type casting and quote handling. Perfect for small projects, scripts, or when you want a simple alternative to vlucas/phpdotenv.

Features

  • Load .env files into $_ENV automatically
  • Supports export keyword
  • Inline comment handling (# comment)
  • Quote string handling ("string" or 'string')
  • Automatic type casting:
    • "true" / "false"bool
    • Numeric strings → int or float
    • "null"null
  • Static helper method for convenience
  • Comprehensive PHPUnit test coverage

Installation

Via Composer (recommended)

composer require darlanschmeller/php-env-loader

Include in your project:

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

use DarlanSchmeller\EnvLoader\EnvLoader;

From source (for development only)

git clone https://github.com/DarlanSchmeller/php-env-loader.git

Include in your project:

require __DIR__ . '/src/EnvLoader.php';

use DarlanSchmeller\EnvLoader\EnvLoader;

Usage

Basic Usage

$env = new EnvLoader(); // Defaults to '../.env'
$variables = $env->load();

var_dump($variables); // Loaded env variables
var_dump($_ENV);      // Also accessible globally

Static Convenience

If you just want to load a .env without instantiating the class:

$variables = EnvLoader::loadFrom(__DIR__ . '/.env');

Sample .env

DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD="supersecret"
APP_DEBUG=true
TIMEOUT=5.5

After loading

$_ENV['DB_PORT'];      // int(3306)
$_ENV['DB_PASSWORD'];  // string("supersecret")
$_ENV['APP_DEBUG'];    // bool(true)
$_ENV['TIMEOUT'];      // float(5.5)

Note

  • Inline comments are supported outside quotes, e.g., DB_HOST=127.0.0.1 # main database host
  • Quotes around values are stripped automatically
  • Empty strings and "null" values are converted to null

Running Automated Tests

Run all PHPUnit tests for this library:

./vendor/bin/phpunit tests

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固