devinci-it/envngine 问题修复 & 功能扩展

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

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

devinci-it/envngine

最新稳定版本:v1.0.0

Composer 安装命令:

composer require devinci-it/envngine

包简介

Tiny schema-first environment loader for PHP apps

README 文档

README

Tiny schema-first environment loader for PHP 8.1+.

Quick Flow

  1. Add your schema in config/env.php.
  2. Boot the registry with Env::boot('config/env.php').
  3. Read values with Env::get(), Env::string(), Env::int(), Env::bool(), or Env::array().
  4. Generate or secure .env with the provided CLI tools if needed.

Builder Config

config/env.php can return a direct builder chain, which is the easiest format to remember:

<?php

use DevinciIT\EnvNgine\EnvBuilder;

return EnvBuilder::make()
    ->string('APP_NAME')
    ->default('EnvNgine App')
    ->description('Application display name')

    ->string('APP_ENV')
    ->default('local')

    ->bool('APP_DEBUG')
    ->default(false)

    ->int('APP_PORT')
    ->default(8000)
    ->required()
    ->description('Application port')

    ->array('ALLOWED_HOSTS')
    ->default(['localhost'])
    ->description('Comma-separated list of allowed hostnames')

    ->string('DB_HOST')
    ->required()
    ->default('127.0.0.1')
    ->description('Database hostname');

Access Values

Boot once, then read values anywhere:

Env::boot(__DIR__ . '/config/env.php');

$appName = Env::string('APP_NAME', 'My App');
$appEnv = Env::string('APP_ENV', 'local');
$appDebug = Env::bool('APP_DEBUG', false);
$appPort = Env::int('APP_PORT', 8000);
$hosts = Env::array('ALLOWED_HOSTS', ['localhost']);
$dbHost = Env::string('DB_HOST', '127.0.0.1');

Helpers:

env_boot(__DIR__ . '/config/env.php');
$registry = env_registry();
$value = Env::get('KEY', 'fallback');

CLI Tools

  • php bin/generate-env.php generates .env from config/env.php.
  • php bin/secure-env.php applies permissions and optional owner/group changes.
  • Composer shortcuts are available through the env:generate, env:secure, and env:prepare scripts.

Caveats

  • Boot is lazy by default, but calling Env::boot() locks the registry.
  • config/env.php is only loaded from the consumer project path or when passed explicitly.
  • Missing .env or missing schema files produce a clear bootstrap error instead of a raw dotenv exception.
  • Access warnings are meant as diagnostics, so they are intentionally visible in CLI output.
  • Array values are parsed from comma-separated strings.
  • Defaults are applied from the schema when a key is missing.
  • The registry becomes immutable after boot, so set runtime values before locking if you need to.

Package Surface

  • Env::boot() / Env::bootWithSchema()
  • Env::get() / Env::string() / Env::int() / Env::bool() / Env::array()
  • env_boot() / env_registry()
  • bin/generate-env.php
  • bin/secure-env.php

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固