solophp/dotenv 问题修复 & 功能扩展

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

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

solophp/dotenv

最新稳定版本:v1.0.0

Composer 安装命令:

composer require solophp/dotenv

包简介

Simple, zero-dependency .env loader for PHP. Loads files into $_ENV with optional $_SERVER population.

README 文档

README

Latest Version on Packagist License PHP Version

Simple, zero-dependency .env loader for PHP. Loads environment variables from files into $_ENV (optionally also $_SERVER). No global putenv calls, no magic variable expansion.

Features

  • Small and focused: just parsing and loading
  • Zero dependencies
  • Deterministic overrides: later files in the same call override earlier ones
  • Typed accessors: string, int, bool, and required

Installation

composer require solophp/dotenv

Quick start

use Solo\Dotenv\Dotenv;

Dotenv::load(__DIR__, ['.env', '.env.local']);

$dbDsn = Dotenv::required('DB_DSN');
$isDebug = Dotenv::bool('APP_DEBUG', false);

API

  • Dotenv::load(string $baseDir, array $filenames = ['.env', '.env.local'], bool $overwrite = false, bool $populateServer = false): void
    • Loads files in order. Existing environment variables set before the call are preserved by default. Variables set by earlier files in the same call can be overridden by later files.
    • Set $overwrite = true to overwrite any existing $_ENV values.
    • Set $populateServer = true to mirror values into $_SERVER.
  • Dotenv::get(string $key, mixed $default = null): mixed
  • Dotenv::string(string $key, string $default = ''): string
  • Dotenv::int(string $key, int $default = 0): int
  • Dotenv::bool(string $key, bool $default = false): bool
  • Dotenv::required(string $key): string — throws InvalidArgumentException if missing/empty.

Parser

The parser is implemented in Solo\Dotenv\EnvParser and supports:

  • Lines like KEY=VALUE
  • Optional leading export
  • Single and double quotes
  • Inline comments for unquoted values (FOO=bar # comment)
  • No variable expansion (by design)

Testing

composer install
composer test

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固