承接 lane4core/dotenv 相关项目开发

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

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

lane4core/dotenv

最新稳定版本:1.0.0

Composer 安装命令:

composer require lane4core/dotenv

包简介

Advanced functions dotEnv tool for reading .env files for standard global and protected contexts

README 文档

README

Build Status

A support tool for reading .env files in global and protected contexts

Description

Lane4 core DotEnv enables reading .env* files according to the well-established rules for .env files. The extracted values can be made available either in the global $_ENV variable or in protected contexts, such as an application domain.

The .env* files must be placed in a subdirectory and read using the loadPublic($path) anf loadPrivate($path) methods. This approach allows for different settings compared to the global $_ENV without causing interference. This is particularly useful when refactoring a monolithic application and creating protected areas with their own values within an existing application.

Features

  • Read .env* files in a protected context
  • .env files with arrays and typecasting

Example Code

use lane4core\DotEnv\DotEnv;

$dotEnv = new DotEnv();
$dotEnv->loadPublic($appRootPath);
$domainEnv = $dotEnv->loadPrivate($domainRootPath);

Data Types

The tool recognizes and processes the following data types:

  • string
  • bool
  • numerics (int, float)
  • array (with type casting of values)

A special feature is the support for both numeric and associative arrays in .env* files.

TYPE_INT=1
TYPE_BOOL=true
TYPE_STRING=teststring
TYPE_ARRAY=[1,2,3,test=>hello,test2=>true,test3=>[1,2,3,4]]

DB_HOST=testHost
DB_NAME=testName
HOME=~
DATABASE_URL=mysql://${DB_HOST}:${DB_NAME}@localhost

Special Features

You also have the option to customize three strategies for processing .env files via constructor injection.

    public function __construct(
        ?GetFilesFromPath $fileFinder = null,
        ?GetValuesFromFiles $fileContentReader = null,
        ?CastTypeHandler $castTypeHandler = null
    ) {
        $this->getFilesFromPath = $fileFinder ?? new GetFilesFromPath();
        $this->castTypeHandler = $castTypeHandler ?? new CastTypeHandler();
        $this->getValuesFromFiles = $fileContentReader ?? new GetValuesFromFiles($this->castTypeHandler);
    }

With this approach, you can customize how .env files are searched (GetFilesFromPath), how values are read from the files (GetValuesFromFiles), and how type conversion (CastTypeHandler) is handled.

Quickstart with Composer

composer require lane4hub/dotenv
make install

Contents in the GitHub Repository

  • Source Files:
    • src
    • tests
  • Support:
    • Docker Compose
    • .env
    • pre-commit-hook.sh
    • Makefile (Simply run make in the console)
  • Documentation:
    • README.md

统计信息

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

GitHub 信息

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

其他信息

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