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
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, andrequired
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 = trueto overwrite any existing$_ENVvalues. - Set
$populateServer = trueto mirror values into$_SERVER.
Dotenv::get(string $key, mixed $default = null): mixedDotenv::string(string $key, string $default = ''): stringDotenv::int(string $key, int $default = 0): intDotenv::bool(string $key, bool $default = false): boolDotenv::required(string $key): string— throwsInvalidArgumentExceptionif 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
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-19