diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-05 19:00:46 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-05 19:00:46 +0900 |
| commit | 7fb4fbeee97dbce19276f28c21394b651832771c (patch) | |
| tree | 9c2233bd57eedbb08bdce3cdf447071a54bdde1a /crates/shirabe/src/command/base_command.rs | |
| parent | 90ebddc8fd17bac1064fb5a0da88a9ad535f5a3c (diff) | |
| download | php-shirabe-7fb4fbeee97dbce19276f28c21394b651832771c.tar.gz php-shirabe-7fb4fbeee97dbce19276f28c21394b651832771c.tar.zst php-shirabe-7fb4fbeee97dbce19276f28c21394b651832771c.zip | |
fix(base-command): honour Application plugin/script disable defaults
BaseCommand::createComposerInstance and initialize() OR in the
Application's getDisablePluginsByDefault()/getDisableScriptsByDefault()
on top of the --no-plugins/--no-scripts flags; this was deferred with
a TODO(phase-c) since the shared Application handle wasn't wired up
yet. The same get_application() + downcast pattern used by get_io()
now covers this too.
Diffstat (limited to 'crates/shirabe/src/command/base_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/base_command.rs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 25618c5..3386496 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -372,10 +372,9 @@ impl BaseCommand for BaseCommandData { .borrow() .has_parameter_option(PhpMixed::from(vec!["--no-scripts"]), false); - // PHP: if ($app instanceof Application && $app->getDisablePluginsByDefault()) $disablePlugins = true; - // (same for getDisableScriptsByDefault()). - // TODO(phase-c): these application-default overrides need a shared Application handle - // (deferred), so only the passed/flag values apply. + let (disable_plugins, disable_scripts) = + apply_application_defaults(self.get_application(), disable_plugins, disable_scripts); + let disable_plugins_kind = if disable_plugins { crate::factory::DisablePlugins::All } else { @@ -697,6 +696,29 @@ impl BaseCommand for BaseCommandData { } } +/// PHP: `$application instanceof Application && $application->getDisablePluginsByDefault()` +/// (same for `getDisableScriptsByDefault()`), ORed into the caller's flags. +fn apply_application_defaults( + application: Option< + Rc<RefCell<dyn shirabe_external_packages::symfony::console::application::Application>>, + >, + mut disable_plugins: bool, + mut disable_scripts: bool, +) -> (bool, bool) { + if let Some(application) = application { + let app_ref = application.borrow(); + let app_dyn: &dyn shirabe_external_packages::symfony::console::application::Application = + &*app_ref; + let app = app_dyn + .as_any() + .downcast_ref::<Application>() + .expect("a Composer command's application is a shirabe Application"); + disable_plugins = disable_plugins || app.get_disable_plugins_by_default(); + disable_scripts = disable_scripts || app.get_disable_scripts_by_default(); + } + (disable_plugins, disable_scripts) +} + /// \Composer\Command\BaseCommand::initialize — runs for every Composer command after the /// input is bound. Shared via a free function because Rust has no inheritance; each command's /// `Command::initialize` forwards here so the leaf's `is_self_update_command()` override (and @@ -707,16 +729,14 @@ pub fn base_command_initialize( _output: Rc<RefCell<dyn OutputInterface>>, ) -> anyhow::Result<()> { // initialize a plugin-enabled Composer instance, either local or global - // PHP also ORs in $this->getApplication()->getDisablePluginsByDefault() / - // getDisableScriptsByDefault(). - // TODO(phase-c): the application-default OR-terms need a shared Application handle - // (deferred), so only the input flags are honoured here. - let mut disable_plugins = input + let disable_plugins = input .borrow() .has_parameter_option(PhpMixed::from(vec!["--no-plugins"]), false); - let mut disable_scripts = input + let disable_scripts = input .borrow() .has_parameter_option(PhpMixed::from(vec!["--no-scripts"]), false); + let (mut disable_plugins, mut disable_scripts) = + apply_application_defaults(cmd.get_application(), disable_plugins, disable_scripts); if cmd.is_self_update_command() { disable_plugins = true; |
