diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-23 02:26:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-23 02:26:56 +0900 |
| commit | c644aa4df0dfcd58e3f0a1372611921678ed6c6d (patch) | |
| tree | 715f6b41884c2632047a7f310674293aa30c80fa /crates/shirabe | |
| parent | 421d98d9a52dd036acd5632f9049f4503c9add18 (diff) | |
| download | php-shirabe-c644aa4df0dfcd58e3f0a1372611921678ed6c6d.tar.gz php-shirabe-c644aa4df0dfcd58e3f0a1372611921678ed6c6d.tar.zst php-shirabe-c644aa4df0dfcd58e3f0a1372611921678ed6c6d.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
| -rw-r--r-- | crates/shirabe/src/command/init_command.rs | 25 | ||||
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 49 |
2 files changed, 21 insertions, 53 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index f63014c..a04836d 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -7,7 +7,6 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::composer::spdx_licenses::SpdxLicenses; use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::helper::FormatBlockMessages; -use shirabe_external_packages::symfony::console::helper::FormatterHelper; use shirabe_external_packages::symfony::console::input::ArrayInput; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; @@ -435,17 +434,16 @@ impl Command for InitCommand { fn interact( &mut self, input: Rc<RefCell<dyn InputInterface>>, - _output: Rc<RefCell<dyn OutputInterface>>, + output: Rc<RefCell<dyn OutputInterface>>, ) { let _ = (|| -> anyhow::Result<()> { let io = self.get_io(); // @var FormatterHelper $formatter — PHP: $this->getHelperSet()->get('formatter') - // TODO(phase-c): get_helper_set returns PhpMixed and HelperSet::get is a todo!() stub (per - // the "Symfony stays todo!()" policy), so the typed FormatterHelper cannot be retrieved - // until the Helper trait + typed HelperSet are modelled. - let formatter: FormatterHelper = todo!(); - let _ = &formatter; - let _ = self.get_helper_set(); + let formatter = self + .get_helper_set() + .expect("the init command is registered on an application before interact() runs") + .borrow() + .get_formatter(); // initialize repos if configured let repositories: Vec<String> = input @@ -523,7 +521,7 @@ impl Command for InitCommand { io.write_error3( &format!( "\n{}\n", - formatter.format_block( + formatter.borrow().format_block( FormatBlockMessages::String( "Welcome to the Composer config generator".to_string(), ), @@ -695,6 +693,7 @@ impl Command for InitCommand { }), None, minimum_stability_default + .clone() .map(PhpMixed::String) .unwrap_or(PhpMixed::Null), )?; @@ -796,8 +795,8 @@ impl Command for InitCommand { let requirements = if (require.len() as i64) > 0 || io.ask_confirmation(question, true) { self.determine_requirements( - input, - _output, + input.clone(), + output.clone(), require, platform_repo.as_ref(), &preferred_stability, @@ -826,8 +825,8 @@ impl Command for InitCommand { let dev_requirements = if (require_dev.len() as i64) > 0 || io.ask_confirmation(question, true) { self.determine_requirements( - input, - _output, + input.clone(), + output.clone(), require_dev, platform_repo.as_ref(), &preferred_stability, diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index c3287e7..8112e18 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -22,23 +22,18 @@ use shirabe_external_packages::symfony::console::exception::missing_input_except use shirabe_external_packages::symfony::console::exception::namespace_not_found_exception::NamespaceNotFoundException; use shirabe_external_packages::symfony::console::exception::runtime_exception::RuntimeException as ConsoleRuntimeException; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; -use shirabe_external_packages::symfony::console::helper::HelperInterface; use shirabe_external_packages::symfony::console::helper::HelperSet; -use shirabe_external_packages::symfony::console::helper::HelperSetKey; use shirabe_external_packages::symfony::console::helper::QuestionHelper; -use shirabe_external_packages::symfony::console::helper::debug_formatter_helper::DebugFormatterHelper; use shirabe_external_packages::symfony::console::helper::formatter_helper::{ FormatBlockMessages, FormatterHelper, }; use shirabe_external_packages::symfony::console::helper::helper::Helper; -use shirabe_external_packages::symfony::console::helper::process_helper::ProcessHelper; use shirabe_external_packages::symfony::console::input::InputDefinition; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::input::InputOption; use shirabe_external_packages::symfony::console::input::argv_input::ArgvInput; use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_argument::InputArgument; -use shirabe_external_packages::symfony::console::input::input_aware_interface::InputAwareInterface; use shirabe_external_packages::symfony::console::output::ConsoleOutputInterface; use shirabe_external_packages::symfony::console::output::console_output::ConsoleOutput; use shirabe_external_packages::symfony::console::output::output_interface::{ @@ -1633,33 +1628,10 @@ impl Application { } /// Gets the default helper set with the helpers that should always be available. + /// + /// The closed set of four helpers is instantiated by `HelperSet::new()` itself. pub fn get_default_helper_set(&self) -> std::rc::Rc<std::cell::RefCell<HelperSet>> { - let helper_set = std::rc::Rc::new(std::cell::RefCell::new(HelperSet::default())); - let helpers: IndexMap<HelperSetKey, std::rc::Rc<std::cell::RefCell<dyn HelperInterface>>> = { - let mut m: IndexMap< - HelperSetKey, - std::rc::Rc<std::cell::RefCell<dyn HelperInterface>>, - > = IndexMap::new(); - m.insert( - HelperSetKey::Int(0), - std::rc::Rc::new(std::cell::RefCell::new(FormatterHelper::default())), - ); - m.insert( - HelperSetKey::Int(1), - std::rc::Rc::new(std::cell::RefCell::new(DebugFormatterHelper::default())), - ); - m.insert( - HelperSetKey::Int(2), - std::rc::Rc::new(std::cell::RefCell::new(ProcessHelper::default())), - ); - m.insert( - HelperSetKey::Int(3), - std::rc::Rc::new(std::cell::RefCell::new(QuestionHelper::default())), - ); - m - }; - HelperSet::new(&helper_set, helpers); - helper_set + HelperSet::new() } /// Returns abbreviated suggestions in string format. @@ -2887,15 +2859,12 @@ impl ApplicationHandle { output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, ) -> anyhow::Result<i32> { let application = &self.0; - if let Some(helper_set) = command.borrow().get_helper_set() { - for (_alias, helper) in helper_set.borrow().get_iterator() { - // if ($helper instanceof InputAwareInterface) $helper->setInput($input); - // TODO(review): downcasting a HelperInterface to InputAwareInterface is not - // expressible without a typed mechanism; needs design. - let _ = helper; - let _ = std::marker::PhantomData::<dyn InputAwareInterface>; - } - } + // PHP: foreach ($command->getHelperSet() as $helper) { if ($helper instanceof + // InputAwareInterface) $helper->setInput($input); } + // TODO(plugin): the HelperSet is now a closed set of four helpers, none of which implement + // InputAwareInterface, so this loop is a no-op. Plugin-registered InputAware helpers cannot + // be reached until dynamic helper registration is restored (see HelperSet). + let _ = command.borrow().get_helper_set(); if !application.borrow().signals_to_dispatch_event.is_empty() { // $commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [] |
