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
- Add your schema in
config/env.php. - Boot the registry with
Env::boot('config/env.php'). - Read values with
Env::get(),Env::string(),Env::int(),Env::bool(), orEnv::array(). - Generate or secure
.envwith 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.phpgenerates.envfromconfig/env.php.php bin/secure-env.phpapplies permissions and optional owner/group changes.- Composer shortcuts are available through the
env:generate,env:secure, andenv:preparescripts.
Caveats
- Boot is lazy by default, but calling
Env::boot()locks the registry. config/env.phpis only loaded from the consumer project path or when passed explicitly.- Missing
.envor 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.phpbin/secure-env.php
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-11