定制 lirien/env 二次开发

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

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

lirien/env

最新稳定版本:1.0.1

Composer 安装命令:

composer require lirien/env

包简介

A minimal and straightforward .env file loader for PHP

README 文档

README

Latest Version PHP Version Total Downloads License

A minimal and straightforward .env file loader for PHP 8.1+.

Ideal for small to medium-sized projects that need simple environment variable loading without additional dependencies.

Installation

composer require lirien/env

Usage

use Lirien\Support\Env;

// Load the .env file (typically at application bootstrap)
Env::load(__DIR__ . '/../.env');

// Retrieve a variable
$appName = Env::get('APP_NAME');

// Set a variable at runtime (e.g. in tests)
Env::set('APP_ENV', 'testing');

Example .env

APP_NAME=Lirien
APP_ENV=local
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=secret

# Comments and empty lines are ignored
REDIS_HOST=127.0.0.1

Methods

  • Env::load(string $path) - Loads variables from the specified .env file

  • Env::get(string $key): string - Returns the environment variable value

  • Env::set(string $key, string value): void - Sets or overrides a variable at runtime

Tip: Always provide a default value when using Env::get() if the variable might not exist.

Security & Best Practices

  • Never commit your .env file — it must stay out of version control

  • Store the .env file outside the public web root

  • Validate and sanitize values loaded from the environment

  • Use Env::set() for tests or runtime overrides, not for permanent configuration

License

This project is licensed under the MIT License. See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-09