Skip to content

Add Reader::eject() to generate a static settings.php - #17

Open
back-2-95 wants to merge 2 commits into
mainfrom
add-reader-eject
Open

back-2-95 wants to merge 2 commits into
mainfrom
add-reader-eject

Conversation

@back-2-95

Copy link
Copy Markdown
Member

Summary

  • Adds Druidfi\Omen\Reader::eject(get_defined_vars()) as a drop-in replacement for Reader::get(): it returns the same ['config', 'databases', 'settings'] array, and additionally writes settings.ejected.php next to settings.php for review.
  • The generated file is a static rewrite of the currently-detected configuration with no dependency on this library: the detected system's getenv()-based translation logic inlined, Defaults' dev/test/prod branches rendered as match ($app_env) {...}, and any existing all.settings.php/dev.settings.php/test.settings.php/prod.settings.php inlined (local.settings.php/local.services.yml are intentionally left dynamic, not inlined).
  • eject() never deletes or renames anything itself - it's meant for the "leaving Druid / leaving the dynamic-detection model" workflow: temporarily swap get() for eject(), trigger one request, review the generated file, then rename/delete/composer remove manually. Workflow documented in CLAUDE.md.
  • Every System class (Ddev, Lagoon, Lando, Pantheon, Tugboat, Upsun, Wodby) now implements a new getEjectedCode() method mirroring its own getEnvs()/setConfiguration() logic as static PHP.

Test plan

  • composer test (all 8 systems × dev/test/prod = 24 runs) passes
  • Added testEject() to DdevTest, LagoonTest, UnknownTest: asserts eject() returns the same conf as get(), and that actually require-ing the generated settings.ejected.php reproduces the same $config/$databases/$settings
  • Manually verified byte-for-byte parity (via a throwaway script, not committed) between Reader::get() and executing the generated file for all 8 systems, which caught and fixed two fidelity bugs before this PR: a port string/int mismatch, and a missing DRUSH_OPTIONS_URI fallback for the no-system-detected case

🤖 Generated with Claude Code

Some projects eventually need to leave Omen's dynamic detection behind
(e.g. exiting Druid for a single known host). Reader::eject() is a
drop-in replacement for Reader::get() that additionally writes
settings.ejected.php: a static, human-reviewable rewrite of the
currently detected configuration with no Omen dependency - the
detected system's env translation inlined, Defaults' dev/test/prod
branches rendered as match(), and any all.settings.php/{env}.settings.php
inlined. It never deletes or renames anything itself.

Every System class now implements getEjectedCode() to describe its own
eject template, mirroring its getEnvs()/setConfiguration() logic.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@back-2-95 back-2-95 added the enhancement New feature or request label Sep 12, 2026
all.settings.php/{env}.settings.php were already inlined verbatim (so
an include inside one of those already survived), but a project-
specific include tacked on directly in settings.php after the Omen
call - e.g. colosseum's `include 'valkey.settings.php';` for Valkey
config - was silently dropped, since Ejector never read that file.

Ejector now scans the real settings.php for include/include_once/
require/require_once statements with a plain quoted filename and
carries them forward verbatim into settings.ejected.php.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

1 participant