A view-less Laravel engine for reading and safely editing
.envfiles — one code path behind a programmatic API, a CLI, and an interactive TUI.
laranail/env-kit-headless is the engine of the EnvKit family. Every mutation
flows through one transactional, atomic, guarded, audited commit path — whether you
call it from a controller, an Artisan command, or the interactive editor. It never
renders HTML or handles HTTP; the env-kit-webui
companion drives this engine for the web.
use Simtabi\Laranail\EnvKit\Headless\Facades\EnvKit;
EnvKit::set('MAIL_HOST', 'smtp.acme.test'); // atomic · backed-up · audited
$debug = EnvKit::getBool('APP_DEBUG', false); // typed readEditing .env from code is deceptively risky: a half-written file, a clobbered
concurrent edit, a leaked secret in a log, or an accidental production write. EnvKit
makes those failure modes impossible by construction:
-
Format-preserving — comments, blank lines, quoting, ordering, EOL and BOM all
survive a round-trip (conformant with
vlucas/phpdotenv). -
Atomic & self-healing — write to a temp file,
fsync, rename; verify the result and auto-rollback on mismatch. Optimistic concurrency rejects clobbering writes. -
Secret-safe — secret-shaped values are redacted from logs, exceptions, audit
records and events. Optional per-value encryption-at-rest, plus cryptographic
secret generators (
token/hex/base64/app_key). -
Validated — declare a schema (config-seeded or fluent)
and gate CI/deploys on
EnvKit::assertValid()orenv:validate. Keep.envaligned with its.env.exampleviaenv:sync/env:check. -
Guarded — production-write protection and a layered protected/hidden/editable key
policy on every surface (programmatic, CLI, TUI), plus a pluggable
authorization gate + write observers. Every CLI command
prints a
PRODUCTION …banner whenAPP_ENV=production. - Observable — a full lifecycle event set (redacted, actor-attributed) and opt-in operator notifications.
- Open/Closed — reshape the engine from your own service provider with zero source edits (fluent DSL, Macroable, driver registry, pipeline middleware, container tags).
composer require laranail/env-kit-headlessRequires PHP 8.4.1+ and Laravel 13. The service provider and EnvKit facade
auto-register. Publish the config if you want to tune it:
php artisan vendor:publish --tag=env-kit-configSee docs/installation.md for details.
Programmatic — Facade, DI of EnvKitInterface, or the env_kit() helper:
EnvKit::set('FEATURE_X', 'true');
EnvKit::transaction(fn ($s) => $s->set('A', '1')->set('B', '2')); // one commit
$value = env_kit('APP_NAME', 'Laravel');Migrating off jackiedo/dotenv-editor? EnvKit exposes the jackiedo-named aliases
(getValue/setKey/deleteKey/…) and a drop-in Compat\DotenvEditor facade, so
existing call sites move over with a class swap — see
Programmatic API.
CLI — 23 commands under laranail::env-kit-headless.*, each with a short env:* alias:
php artisan env:set MAIL_HOST=smtp.acme.test
php artisan env:get APP_NAME
php artisan env:doctor # health-check rules
php artisan env:export --format=json --output=env.json # also csv / dotenv / yamlTUI — an interactive editor on laravel/prompts:
php artisan env:edit// config/env-kit.php (excerpt)
'auto_commit' => true, // immediate writes
'auto_backup' => true, // snapshot before each write
'protect_production'=> true, // block prod writes unless overridden
'protected_keys' => ['APP_KEY', 'DB_PASSWORD'], // never writable
'hidden_keys' => ['*_PASSWORD', '*_SECRET'], // masked in listings
'audit' => ['enabled' => true],
'encryption' => ['driver' => 'laravel'],Full reference: docs/configuration.md.
| Page | What it covers |
|---|---|
| Installation | Requirements, install, publishing config, the ENV_KIT_PATH override |
| Configuration | Every config key, layered key policy, schema precedence |
| Architecture | The document model, commit pipeline, atomic writer, security core |
| Extending |
configure() DSL, Macroable, EnvKitManager, pipeline middleware, custom drivers, tag-based registration |
| Authorization | The update gate + write observers, the Laravel-ability bridge, the "which seam" table |
| Events | The lifecycle event table, actor attribution, listening |
| Notifications | Opt-in operator alerts, channels, testing |
| Release | Versioning, the release workflow, trusted publishing |
| Programmatic API | Reads, typed getters, the three write modes, schema, .env.example sync, secret generators, EnvKit::fake()
|
| CLI | All 23 commands, exit-code contract, --file / --force-production
|
| Schema | Declarative validation, the rule set, MatchesEnvSchema for FormRequests |
| TUI | The interactive env:edit editor |
| Encryption | Per-value encryption-at-rest, cipher drivers |
| Doctor | Health-check rules and writing your own |
| Import / Export | The Porter, JSON/CSV/dotenv/YAML formats, custom formats |
| Audit & Events | Audit sinks, the AfterWrite event, redaction |
The rendered docs live at https://opensource.simtabi.com/env-kit-headless/docs/.
EnvKit handles secrets. Secret-shaped values never reach logs, exception messages,
audit records, or events. Found a vulnerability? See SECURITY.md —
report privately to opensource@simtabi.com.
PRs welcome — see CONTRIBUTING.md. Run vendor/bin/pest,
vendor/bin/phpstan analyse (level 9), and vendor/bin/pint before submitting.
MIT © Simtabi LLC. See LICENSE.