Design issue CLI \XF::app() not loaded when registering commands

Xon

Well-known member
Affected version
2.0.1
When CLI commands are registered, the XF app state has not yet been loaded.

This means the CLI command description (AbstractRebuildCommand::getRebuildDescription) can not be varied based off XF options.

This is also fairly unexpected that add-on code can be run before the XF app is setup.
 
This isn't really something we can change. The app gets instantiated after it is determined what command-type needs to run, for example we might be calling the Install app (this is done using the static getCustomAppClass() method) so we can't just arbitrarily register an app in time for configure() to be called, and even if we could, doing so would mean a full app instantiation for every available command when any command is run, as configure() needs to be called for every available command during $this->registerCommands($console); in the Runner.

Fundamentally, I don't think we can do anything about this, but I'll leave it open for the time being while we think it over.
 
Does it make sense that touching \XF::app() before the app is initialized creates an XF app?

Throwing a logic exception about not being able to touch the XF app without calling setupApp would at least hint in the right direction, rather than the duplicate setupApp exception later.

Every XF entry point explicitly sets the XF app (via runApp or setupApp) anyway.
 
Top Bottom