定制 alanvdb/server-environment 二次开发

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

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

alanvdb/server-environment

最新稳定版本:v1.0

Composer 安装命令:

composer require alanvdb/server-environment

包简介

README 文档

README

A PHP library for managing environment variables with strict type checking and comprehensive error handling.

Features

  • Secure environment variable management
  • Strict type enforcement
  • Immutable system environment variables
  • Easy-to-use interface for retrieving environment variables
  • Comprehensive exception handling

Installation

Install via Composer:

composer require alanvdb/server-environment

Usage

Basic Usage

use AlanVdb\Server\ServerEnvironment;

// Create an environment with optional initial variables
$env = new ServerEnvironment([
    'APP_DEBUG' => 'true',
    'APP_ENV' => 'development'
]);

// Retrieve an environment variable
$debugMode = $env->get('APP_DEBUG'); // returns 'true'

// Check if a variable exists
$hasEnv = $env->has('APP_ENV'); // returns true

Error Handling

use AlanVdb\Server\Exception\EnvironmentVariableNotFound;
use AlanVdb\Server\Exception\CannotMutateEnvironmentVariable;

try {
    // Attempting to get a non-existent variable will throw an exception
    $value = $env->get('NON_EXISTENT_VAR');
} catch (EnvironmentVariableNotFound $e) {
    // Handle missing variable
}

try {
    // Attempting to modify a system environment variable will throw an exception
    $env = new ServerEnvironment(['PATH' => '/custom/path']);
} catch (CannotMutateEnvironmentVariable $e) {
    // Handle mutation attempt
}

Factory

use AlanVdb\Server\ServerEnvironmentFactory;

$factory = new ServerEnvironmentFactory();
$env = $factory->create([
    'APP_DEBUG' => 'true',
    'APP_ENV' => 'development'
]);

Requirements

  • PHP 8.2+
  • Composer

Key Design Principles

  • Immutability of system environment variables
  • Type safety
  • Clear and descriptive exceptions
  • Easy integration with existing PHP projects

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固