diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-12 02:14:18 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-12 02:15:32 +0900 |
| commit | 981cae63d9777b877aa9f96907c7995ec020fbf9 (patch) | |
| tree | d1e9129ece95f1fa3750bb9a7302135d397e0abf /crates/shirabe-external-packages/src/symfony | |
| parent | 1e44f5723e4c0e0903d00a61f254901e612fe5e1 (diff) | |
| download | php-shirabe-981cae63d9777b877aa9f96907c7995ec020fbf9.tar.gz php-shirabe-981cae63d9777b877aa9f96907c7995ec020fbf9.tar.zst php-shirabe-981cae63d9777b877aa9f96907c7995ec020fbf9.zip | |
feat(php-shim): implement runtime functions to run --version
Replace todo!() stubs reached on the `composer --version` path so the
command runs without panicking and exits cleanly:
- introspection (function_exists, class_exists, extension_loaded,
defined) via white-lists modeling a standard Linux PHP CLI
- type casts: php_to_string/strval, php_truthy/boolval, substr,
byte_at, explode, strtr_array
- config/env: error_reporting, ini_get, date_default_timezone_*,
server_get/server_contains_key, php_uname("s")
- IO: turn PhpResource into an enum (Stdin/Stdout/Stderr/File) and
implement fwrite/fflush/stream_isatty/php_fopen resource helpers
- shutdown/exit: register_shutdown_function + run_shutdown_functions,
exit, error_get_last
- preg_match_all_offset_capture via the regex crate; the formatter
pattern drops PCRE possessive quantifiers (original kept in a
comment with a TODO)
proc_open reports unavailable for now (TODO(phase-c)); terminal-size
and tty detection fall back to defaults. sprintf calls on this path
are rewritten with format!(). OutputFormatterStyleInterface gains
clone_box to return shared styles.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony')
6 files changed, 27 insertions, 30 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/application.rs b/crates/shirabe-external-packages/src/symfony/console/application.rs index 83309f4..e15b68d 100644 --- a/crates/shirabe-external-packages/src/symfony/console/application.rs +++ b/crates/shirabe-external-packages/src/symfony/console/application.rs @@ -546,13 +546,7 @@ impl Application { pub fn get_long_version(&self) -> String { if "UNKNOWN" != self.get_name() { if "UNKNOWN" != self.get_version() { - return shirabe_php_shim::sprintf( - "%s <info>%s</info>", - &[ - PhpMixed::from(self.get_name()), - PhpMixed::from(self.get_version()), - ], - ); + return format!("{} <info>{}</info>", self.get_name(), self.get_version()); } return self.get_name(); diff --git a/crates/shirabe-external-packages/src/symfony/console/color.rs b/crates/shirabe-external-packages/src/symfony/console/color.rs index 8dfce9e..4bf52f3 100644 --- a/crates/shirabe-external-packages/src/symfony/console/color.rs +++ b/crates/shirabe-external-packages/src/symfony/console/color.rs @@ -50,7 +50,7 @@ fn available_options_get(name: &str) -> Option<(i64, i64)> { .map(|(_, v)| *v) } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Color { foreground: String, background: String, @@ -119,10 +119,7 @@ impl Color { return String::new(); } - shirabe_php_shim::sprintf( - "\u{1b}[%sm", - &[shirabe_php_shim::implode(";", &set_codes).into()], - ) + format!("\u{1b}[{}m", shirabe_php_shim::implode(";", &set_codes)) } pub fn unset(&self) -> String { @@ -140,10 +137,7 @@ impl Color { return String::new(); } - shirabe_php_shim::sprintf( - "\u{1b}[%sm", - &[shirabe_php_shim::implode(";", &unset_codes).into()], - ) + format!("\u{1b}[{}m", shirabe_php_shim::implode(";", &unset_codes)) } fn parse_color(color: &str, background: bool) -> Result<String, InvalidArgumentException> { diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs index 413f023..4a451d9 100644 --- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs +++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs @@ -95,12 +95,8 @@ impl OutputFormatter { &self, string: &str, ) -> anyhow::Result<Option<Box<dyn OutputFormatterStyleInterface>>> { - if self.styles.contains_key(string) { - // PHP returns the shared style instance; ownership cannot be expressed without Clone - // on the trait object. - // TODO(human-review): returning a shared style here needs an Rc/Clone strategy in - // Phase C. - return Ok(Some(todo!())); + if let Some(style) = self.styles.get(string) { + return Ok(Some(style.clone_box())); } let mut matches: Vec<Vec<String>> = vec![]; @@ -281,8 +277,15 @@ impl WrappableOutputFormatterInterface for OutputFormatter { let mut offset: i64 = 0; let mut output = String::new(); - let open_tag_regex = "[a-z](?:[^\\\\<>]*+ | \\\\.)*"; - let close_tag_regex = "[a-z][^<>]*+"; + // Accurate PCRE patterns (possessive quantifiers `*+`), unsupported by the + // `regex` crate: + // let open_tag_regex = "[a-z](?:[^\\\\<>]*+ | \\\\.)*"; + // let close_tag_regex = "[a-z][^<>]*+"; + // TODO(phase-c): restore the possessive quantifiers once a PCRE-compatible + // engine is available; greedy quantifiers match the same tags here but may + // differ in pathological backtracking cases. + let open_tag_regex = "[a-z](?:[^\\\\<>]* | \\\\.)*"; + let close_tag_regex = "[a-z][^<>]*"; let mut current_line_length: i64 = 0; let mut matches: shirabe_php_shim::PregOffsetCaptureMatches = Default::default(); shirabe_php_shim::preg_match_all_offset_capture( diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style.rs index 835bcd6..a8540de 100644 --- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style.rs +++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style.rs @@ -2,7 +2,7 @@ use crate::symfony::console::color::Color; use crate::symfony::console::formatter::output_formatter_style_interface::OutputFormatterStyleInterface; /// Formatter style class for defining styles. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct OutputFormatterStyle { color: Color, foreground: String, @@ -93,4 +93,8 @@ impl OutputFormatterStyleInterface for OutputFormatterStyle { self.color.apply(&text) } + + fn clone_box(&self) -> Box<dyn OutputFormatterStyleInterface> { + Box::new(self.clone()) + } } diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_interface.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_interface.rs index c9a2648..6fe4846 100644 --- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_interface.rs +++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter_style_interface.rs @@ -17,4 +17,9 @@ pub trait OutputFormatterStyleInterface: std::fmt::Debug { /// Applies the style to a given text. fn apply(&mut self, text: &str) -> String; + + /// Clones the style into a new boxed trait object. PHP shares the style + /// instance by reference; styles are immutable once configured, so cloning + /// is behaviorally equivalent here. + fn clone_box(&self) -> Box<dyn OutputFormatterStyleInterface>; } diff --git a/crates/shirabe-external-packages/src/symfony/console/terminal.rs b/crates/shirabe-external-packages/src/symfony/console/terminal.rs index 8163b28..5ff744a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/terminal.rs +++ b/crates/shirabe-external-packages/src/symfony/console/terminal.rs @@ -127,11 +127,8 @@ impl Terminal { /// Returns whether STDOUT has vt100 support (some Windows 10+ configurations). fn has_vt100_support() -> bool { shirabe_php_shim::function_exists("sapi_windows_vt100_support") && { - // PHP passes the `fopen('php://stdout', 'w')` resource. The shim's `fopen` - // returns `PhpMixed` but `sapi_windows_vt100_support` expects - // `&PhpResource`; bridge with a placeholder resource. - let _ = shirabe_php_shim::fopen("php://stdout", "w"); - shirabe_php_shim::sapi_windows_vt100_support(&shirabe_php_shim::PhpResource) + let stream = shirabe_php_shim::php_fopen_resource("php://stdout", "w"); + shirabe_php_shim::sapi_windows_vt100_support(&stream) } } |
