From c644aa4df0dfcd58e3f0a1372611921678ed6c6d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 23 Jun 2026 02:26:56 +0900 Subject: refactor(console): close HelperSet to a fixed set of four helpers Replace the dynamic, string-keyed HelperSet (set/has/get/get_iterator, HelperSetKey, deprecated set_command/get_command) with a closed set of FormatterHelper, DebugFormatterHelper, ProcessHelper and QuestionHelper instantiated by an argument-less constructor and exposed through typed getters (get_formatter/get_debug_formatter/get_process/get_question). The typed getters let ProcessHelper, QuestionHelper::write_error and InitCommand::interact drop their downcast/placeholder todo!() stubs. Dynamic registration of plugin-provided helpers is intentionally dropped for now and tracked via TODO(plugin) comments. Co-Authored-By: Claude Opus 4.8 --- .../src/symfony/console/helper/question_helper.rs | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs index db9c094..f2c2a00 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs @@ -5,6 +5,7 @@ use crate::symfony::console::exception::missing_input_exception::MissingInputExc use crate::symfony::console::exception::runtime_exception::RuntimeException; use crate::symfony::console::formatter::output_formatter::OutputFormatter; use crate::symfony::console::formatter::output_formatter_style::OutputFormatterStyle; +use crate::symfony::console::helper::formatter_helper::FormatBlockMessages; use crate::symfony::console::helper::helper::Helper; use crate::symfony::console::helper::helper_interface::HelperInterface; use crate::symfony::console::helper::helper_set::HelperSet; @@ -316,22 +317,17 @@ impl QuestionHelper { output: Rc>, error: &shirabe_php_shim::Exception, ) { - let message; - if let Some(helper_set) = self.get_helper_set() { - if helper_set.borrow().has("formatter") { - // PHP: `$this->getHelperSet()->get('formatter')->formatBlock(...)`. - // HelperSet::get yields `dyn HelperInterface`, which does not have - // `AsAny` as a supertrait, so it cannot be downcast to - // FormatterHelper. Resolved once HelperInterface gains AsAny (see - // report). - let _formatter = helper_set.borrow().get("formatter").unwrap(); - todo!("downcast dyn HelperInterface to FormatterHelper for format_block"); - } else { - message = format!("{}", error.message); - } + let message = if let Some(helper_set) = self.get_helper_set() { + let formatter = helper_set.borrow().get_formatter(); + let message = formatter.borrow().format_block( + FormatBlockMessages::String(error.message.clone()), + "error", + false, + ); + message } else { - message = format!("{}", error.message); - } + format!("{}", error.message) + }; output .borrow() -- cgit v1.3.1