From e93ea9ae1058334fc72b7795021bb42c1bd64401 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jun 2026 00:34:01 +0900 Subject: feat(io): add as_any downcast shims for IOInterface and OutputInterface Introduce the cross-cutting downcast base for PHP `instanceof` checks on io/output trait objects: `IOInterface::as_any` (ConsoleIO/NullIO/BufferIO) and `OutputInterface::as_console_output_interface` (promoting ConsoleOutput to a proper ConsoleOutputInterface). Wire the resolved downcasts in ConsoleIO error output, Auditor table format, and the event dispatcher. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../symfony/component/console/output/console_output.rs | 17 ++++++++++++++++- .../component/console/output/output_interface.rs | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'crates/shirabe-external-packages/src/symfony/component/console/output') diff --git a/crates/shirabe-external-packages/src/symfony/component/console/output/console_output.rs b/crates/shirabe-external-packages/src/symfony/component/console/output/console_output.rs index c834394..332cbd1 100644 --- a/crates/shirabe-external-packages/src/symfony/component/console/output/console_output.rs +++ b/crates/shirabe-external-packages/src/symfony/component/console/output/console_output.rs @@ -1,4 +1,5 @@ use crate::symfony::component::console::formatter::OutputFormatter; +use crate::symfony::component::console::output::ConsoleOutputInterface; use crate::symfony::component::console::output::OutputInterface; #[derive(Debug)] @@ -12,13 +13,27 @@ impl ConsoleOutput { ) -> Self { todo!() } +} + +impl ConsoleOutputInterface for ConsoleOutput { + fn get_error_output(&self) -> &dyn OutputInterface { + todo!() + } - pub fn get_error_output(&self) -> &dyn OutputInterface { + fn set_error_output(&mut self, _error: Box) { todo!() } } impl OutputInterface for ConsoleOutput { + fn is_console_output_interface(&self) -> bool { + true + } + + fn as_console_output_interface(&self) -> Option<&dyn ConsoleOutputInterface> { + Some(self) + } + fn write(&self, _messages: &str, _newline: bool, _type: i64) { todo!() } diff --git a/crates/shirabe-external-packages/src/symfony/component/console/output/output_interface.rs b/crates/shirabe-external-packages/src/symfony/component/console/output/output_interface.rs index 36b6c08..11fb82e 100644 --- a/crates/shirabe-external-packages/src/symfony/component/console/output/output_interface.rs +++ b/crates/shirabe-external-packages/src/symfony/component/console/output/output_interface.rs @@ -1,4 +1,5 @@ use crate::symfony::component::console::formatter::OutputFormatter; +use crate::symfony::component::console::output::ConsoleOutputInterface; pub trait OutputInterface { // PHP class semantics: OutputInterface methods take &self with interior mutability, @@ -21,6 +22,12 @@ pub trait OutputInterface { false } + /// PHP: `$output instanceof ConsoleOutputInterface`. Returns the output as a + /// ConsoleOutputInterface trait object when it is one. Default None; ConsoleOutput overrides. + fn as_console_output_interface(&self) -> Option<&dyn ConsoleOutputInterface> { + None + } + /// PHP: only StreamOutput exposes `getStream()`. Default panics for outputs without one. fn get_stream(&self) -> shirabe_php_shim::PhpResource { todo!("get_stream not available on this OutputInterface implementation") -- cgit v1.3.1