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

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

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

jardispsr/dotenv

最新稳定版本:1.0.0

Composer 安装命令:

composer require jardispsr/dotenv

包简介

This package provides dotenv interface for a domain driven design approach

README 文档

README

Build Status License: MIT PHP Version PHPStan Level PSR-4 PSR-12

A contract-only PHP library that defines the DotEnvInterface for Domain-Driven Design applications.

Overview

This package provides exclusively an interface – no implementation. It serves as an abstraction layer for DotEnv functionality and distinguishes between:

  • Public environment variables (system-wide, loaded into $_ENV)
  • Private environment variables (application-specific, returned as an array)

Installation

composer require jardispsr/dotenv

Interface

namespace JardisPsr\DotEnv;

interface DotEnvInterface
{
    /**
     * Loads public environment variables into the system environment ($_ENV, getenv)
     *
     * @param string $pathToEnvFiles Path to directory containing .env files
     * @throws Exception
     */
    public function loadPublic(string $pathToEnvFiles): void;

    /**
     * Loads and returns private environment variables as an array
     *
     * @param string $pathToEnvFiles Path to directory containing .env files
     * @return array<string, mixed>|null
     * @throws Exception
     */
    public function loadPrivate(string $pathToEnvFiles): mixed;
}

Usage

Implement the interface in your own class:

use JardisPsr\DotEnv\DotEnvInterface;

class MyDotEnv implements DotEnvInterface
{
    public function loadPublic(string $pathToEnvFiles): void
    {
        // Implementation for loading public variables
    }

    public function loadPrivate(string $pathToEnvFiles): mixed
    {
        // Implementation for loading private variables
        return $privateVars;
    }
}

Development

This project uses Docker for all development tasks. Never run Composer, PHPStan, or PHPCS commands directly on the host – always use the Makefile targets.

Prerequisites

  • Docker
  • Docker Compose
  • Make

Available Commands

# Install dependencies
make install

# Update dependencies
make update

# Regenerate autoloader
make autoload

# Check code style (PSR-12)
make phpcs

# Run static analysis (PHPStan Level 8)
make phpstan

# Open container shell
make shell

# Clean up Docker resources
make remove

Quality Standards

PHP_CodeSniffer

  • Standard: PSR-12
  • Line length: 120 (limit), 150 (absolute limit)
  • Strict types required: declare(strict_types=1);

PHPStan

  • Level: 8 (maximum strictness)
  • Analyzed paths: src/

Pre-Commit Hook

After installation, a Git pre-commit hook is automatically set up that:

  1. Validates branch names: (feature|fix|hotfix)/{1-7 digits}_{description} or :{7-40 hex chars}
  2. Validates Git username
  3. Runs PHPCS on staged PHP files
  4. Blocks commits on errors

PHP Requirements

  • Minimum: PHP 8.2
  • Recommended: PHP 8.3

Versioning

This project follows Semantic Versioning. Since this is a contract, breaking changes are rare and only appear in major versions.

License

MIT License - see LICENSE for details.

Support

Authors

Jardis Core Development Team

统计信息

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

GitHub 信息

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

其他信息

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