Repository navigation
Issue/589 Unify the app adapter lifecycle and let the pipeline own an early end of a run - #590
Conversation
The stop flag and the exit code move to AppContext. A stage that stops the context ends the run; the optional closing stage still runs, and the web runtime uses it to send the response.
AppInterface gains boot(). The adapter constructors only store the context, and AppFactory boots the adapter right after creating it.
The pipeline ends the run on a stop, so ResolveRouteStage, HandleRouteNotFoundStage, PrepareRequestStage and DispatchRequestStage no longer check isStopped() themselves.
DebugBarCommand, OpenApiCommand and ResourceCacheClearCommand get the file system in exec() instead of in their constructor, so registering the core commands loads no config. A test guards that registering them needs neither the environment nor any config.
The console boot registers the core commands after the helpers and the app commands at its end, after the environment, the config and the error handler. The new ResolveEnvironmentStage lets core:env, list and help run when the .env file is missing or malformed by stopping the boot; every other command fails with the exception of the environment file. The boot failure, both try/catch blocks of ConsoleAppAdapter and the boot failure branch of RunCommandStage are removed.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Closes #589
What changed
AppInterfacegainsboot(). Both adapter constructors only store the context, andAppFactorycallsboot()right after creating the adapter, soAppFactory::create(...)->start()works as before.stop()on the context ends the run: no later stage runs or dispatches events. An optional closing stage (second constructor argument) runs last, also after a stop, but not after a stage throws.stop(),isStopped(),getExitCode()andsetExitCode()moved toAppContext;WebContextandConsoleContextinherit them.SendResponseStageis the closing stage of the web runtime, andResolveRouteStage,HandleRouteNotFoundStage,PrepareRequestStageandDispatchRequestStageno longer checkisStopped()themselves.InitConsole › LoadHelpers › RegisterCoreCommands › ResolveEnvironment › LoadEnvironment › LoadAppConfig › SetupErrorHandler › SetupConsoleApplication › RegisterAppCommands; the runtime only runs the command.env()andconfig().DebugBarCommand,OpenApiCommandandResourceCacheClearCommandnow get the file system inexec(), and a test fails if registering the core commands loads the environment or any config.ResolveEnvironmentStageloads the.envfile. When it is missing (EnvException) or malformed (InvalidFileException), it stops the boot for a core command that does not require the environment (core:env) and for Symfony'slistandhelp; every other command gets that exception. These two exception types are the only ones caught.$bootFailure, bothtry/catch (Throwable)blocks ofConsoleAppAdapter,ConsoleContext::getBootFailure()and the boot failure branch ofRunCommandStage.RegisterCoreCommandsStageandRegisterAppCommandsStagemoved toQuantum\App\Stages\Boot.core:envcommand name #575, Make the console adapter constructor a plain boot pipeline, like WebAppAdapter #576, Make the web and console contexts extend AppContext, drop their duplicated state, and rename the web pipeline and context #579, Replace the boot, web and console pipelines with one generic Pipeline #583, Unify the app adapter lifecycle and let the pipeline own an early end of a run #589) are merged into one entry that describes the change from 3.0.3, since 3.1.0 is not released and the earlier entries described intermediate states.Why
Both adapters ran the same
Pipeline, but each carried its own control flow. An early end of a web request was handled by hand in four stages, so a new stage could do work on an answered request if it forgot the check. The console boot caught anyThrowable, kept it, carried it into the runtime and rethrew it from two places, treating a broken.envand a broken helper file the same way. Now the pipeline owns an early end, the context owns the state, and no adapter catches anything. It also gives every stage event of #538 one meaning: a stage that runs fires its events, a stage that does not run fires none.Breaking changes
AppInterfacegainsboot(), and creating an adapter no longer boots it. Code that usesAppFactoryis not affected; code that creates an adapter directly must callboot()beforestart().ConsoleContext::getBootFailure()and its constructor argument are removed (both added earlier in 3.1.0).RegisterCoreCommandsStageandRegisterAppCommandsStagemoved fromQuantum\App\Stages\ConsoletoQuantum\App\Stages\Boot..env, an app command that does not require the environment no longer runs, andlistshows only the core commands; a broken app helper file or an error handler that cannot be set up fails every command instead of being tolerated. Both match 3.0.3.Testing
PipelineTest: a stop ends the run and later stages dispatch no events; the closing stage runs with and without a stop, with its events, and not after a throw.AppContextTest: the stop flag and the exit code.WebAppAdapterTest,ConsoleAppAdapterTest: the constructor does not boot,boot()runs the boot stages;AppFactoryTest: the created app is booted.ResolveEnvironmentStageTest: nothing happens on a valid.env; on a missing and on a malformed.env, the boot stops for a command that does not require the environment,listandhelp, and the exception reaches a command that requires the environment, an unknown command and no command.CommandRegistrarTest: registering the core commands with only the helpers loaded loads neither the environment nor any config (fails before the three commands are changed).ConsoleAppAdapterTest: every case of the behavior table of Unify the app adapter lifecycle and let the pipeline own an early end of a run #589, including an app command whose constructor readsenv('APP_KEY').boot()after creating the adapter. The removed tests covered the old boot failure and the per-stageisStopped()guards.master, with identical results:GET /200,GET /api/posts200,OPTIONS /api/posts204 with the CORS headers, a missing page 404 as HTML and as JSON;list,core:versionandpost:showon a valid.env; on a missing and on a malformed.env,listandcore:envrun andcore:key,post:show, an unknown command and no command fail with the env exception.Summary by CodeRabbit
New Features
Bug Fixes
Documentation