diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-26 00:37:53 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-26 00:37:53 +0900 |
| commit | 1bbf06f5c852ed73d73b0dd1b86cd85661e0a610 (patch) | |
| tree | 7e298eb59f2da8ce01cdc469d4b98fba402de0e9 /crates/shirabe-external-packages/src/symfony/console/helper | |
| parent | ed0da7fcc3056ce5a822ac0de63ccc2dc799006e (diff) | |
| download | php-shirabe-1bbf06f5c852ed73d73b0dd1b86cd85661e0a610.tar.gz php-shirabe-1bbf06f5c852ed73d73b0dd1b86cd85661e0a610.tar.zst php-shirabe-1bbf06f5c852ed73d73b0dd1b86cd85661e0a610.zip | |
fix(console-table): wrap cells that exceed the column max width
buildTableRows panicked on the unported formatAndWrap call, so any table
with a max column width (e.g. the audit advisory table) aborted the
process. PHP calls the formatter as a WrappableOutputFormatterInterface;
model that instanceof as an AsAny downcast to OutputFormatter, the sole
implementor in this port.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/helper')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/helper/table.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs index ca0802d0..99c1b6ea 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs @@ -4,6 +4,7 @@ use crate::composer::pcre::preg::Preg; use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; use crate::symfony::console::exception::runtime_exception::RuntimeException; use crate::symfony::console::formatter::output_formatter::OutputFormatter; +use crate::symfony::console::formatter::wrappable_output_formatter_interface::WrappableOutputFormatterInterface; use crate::symfony::console::helper::helper::Helper; use crate::symfony::console::helper::table_cell::{TableCell, TableCellOption}; use crate::symfony::console::helper::table_cell_style::TableCellStyle; @@ -924,11 +925,11 @@ impl Table { && Helper::width(&self.remove_decoration(&cell.to_php_string())) > self.column_max_widths[&column] { - // TODO(phase-b): formatAndWrap requires a WrappableOutputFormatterInterface; - // downcasting dyn OutputFormatterInterface to it needs concrete knowledge. - let _ = colspan; - let wrapped: Option<String> = todo!(); - cell = Cell::Value(wrapped.unwrap_or_default()); + let wrapped = self.format_and_wrap( + &cell.to_php_string(), + self.column_max_widths[&column] * colspan, + ); + cell = Cell::Value(wrapped); } let cell_str = cell.to_php_string(); if shirabe_php_shim::strstr(&cell_str, "\n").is_none() { @@ -1389,6 +1390,22 @@ impl Table { true } + /// `setColumnMaxWidth` guarantees the formatter is a `WrappableOutputFormatterInterface`, and + /// `OutputFormatter` is the sole implementor in this port, so `instanceof` reduces to this + /// downcast. + fn format_and_wrap(&self, string: &str, width: i64) -> String { + let formatter = self.output.borrow().get_formatter(); + let mut formatter = formatter.borrow_mut(); + let formatter = formatter + .as_any_mut() + .downcast_mut::<OutputFormatter>() + .expect("formatter must be a WrappableOutputFormatterInterface"); + formatter + .format_and_wrap(Some(string), width) + .unwrap() + .unwrap_or_default() + } + /// PHP `Helper::removeDecoration($this->output->getFormatter(), $string)`. fn remove_decoration(&self, string: &str) -> String { let formatter = self.output.borrow().get_formatter(); |
