From 1e44f5723e4c0e0903d00a61f254901e612fe5e1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 12 Jun 2026 01:01:35 +0900 Subject: feat(symfony-console): port Symfony Console and make the workspace compile Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/io/buffer_io.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'crates/shirabe/src/io/buffer_io.rs') diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs index 988c153..8c10dee 100644 --- a/crates/shirabe/src/io/buffer_io.rs +++ b/crates/shirabe/src/io/buffer_io.rs @@ -6,11 +6,11 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::formatter::OutputFormatterInterface; 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::input::InputInterface; use shirabe_external_packages::symfony::console::input::StringInput; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_external_packages::symfony::console::output::StreamOutput; use shirabe_php_shim::{ PHP_EOL, PhpMixed, RuntimeException, fopen, fseek, fwrite, rewind, stream_get_contents, strip_tags, @@ -27,7 +27,7 @@ impl BufferIO { verbosity: i64, formatter: Option>, ) -> Result { - let mut input_obj = StringInput::new(&input); + let mut input_obj = StringInput::new(&input)?; input_obj.set_interactive(false); let stream = fopen("php://memory", "rw"); @@ -39,21 +39,34 @@ impl BufferIO { .into()); } - let decorated = formatter.as_ref().map_or(false, |f| f.is_decorated()); - // TODO(phase-c): wire StreamOutput as the output. The console tree merge made StreamOutput - // implement the unified OutputInterface; StreamOutput::new is still a stub. + let _decorated = formatter.as_ref().map_or(false, |f| f.is_decorated()); + // TODO(phase-c): wire StreamOutput as the output. StreamOutput::new requires a + // PhpResource, but `fopen` here yields a PhpMixed; PhpMixed has no resource variant, + // so the stream cannot be passed through yet (same PhpResource/PhpMixed gap noted in + // QuestionHelper). The constructed StreamOutput is therefore not wired as the output. + // formatter, stream and verbosity feed the pending StreamOutput::new wiring below. let _ = formatter; - let _ = StreamOutput::new(stream, verbosity, Some(decorated)); + let _ = stream; + let _ = verbosity; let output: std::rc::Rc> = - todo!("wire StreamOutput as the ConsoleIO output"); + todo!("wire StreamOutput as the ConsoleIO output (needs PhpResource stream)"); + + let question_helper: std::rc::Rc> = + std::rc::Rc::new(std::cell::RefCell::new(QuestionHelper::default())); + let mut helpers: indexmap::IndexMap< + HelperSetKey, + std::rc::Rc>, + > = indexmap::IndexMap::new(); + helpers.insert(HelperSetKey::Int(0), question_helper); + let helper_set = std::rc::Rc::new(std::cell::RefCell::new(HelperSet::default())); + HelperSet::new(&helper_set, helpers); + let helper_set = helper_set.borrow().clone(); - let helpers: Vec>> = - vec![std::rc::Rc::new(std::cell::RefCell::new(QuestionHelper))]; let inner = ConsoleIO::new( std::rc::Rc::new(std::cell::RefCell::new(input_obj)) as std::rc::Rc>, output, - HelperSet::new(helpers), + helper_set, ); Ok(Self { inner }) -- cgit v1.3.1