From 6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 16:16:51 +0900 Subject: refactor(php-shim): introduce PhpClass for reporting PHP class names Rust has no runtime class name, so `Command::get_class` existed purely to let each command hand back its PHP class name, supplied through the two-argument variant of `delegate_command_trait_impls_to_inner!` at the impl site. Replace it with a general `PhpClass` trait plus an `impl_php_class!` macro, so the name is stated once next to the type definition and the mechanism is reusable outside commands. `Command` gains `PhpClass` as a supertrait and drops `get_class`, and `VcsDriverKind`'s hand-rolled `php_class_name` table moves onto the trait. Behavior is unchanged: the same class-name strings are reported, and the base command state still panics when asked for a name it cannot supply. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/symfony/console/command/command.rs | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/command/command.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/command/command.rs b/crates/shirabe-external-packages/src/symfony/console/command/command.rs index 1f1455f8..2af60db0 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/command.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command/command.rs @@ -325,13 +325,6 @@ macro_rules! delegate_command_trait_impls_to_inner { $crate::delegate_to_inner!($field, fn ignore_validation_errors(&self)); $crate::delegate_to_inner!($field, fn get_ignore_validation_errors(&self) -> bool); }; - // Variant taking the command's PHP fully-qualified class name (see `Command::get_class`). - ($field:ident, $fqcn:literal) => { - $crate::delegate_command_trait_impls_to_inner!($field); - fn get_class(&self) -> String { - $fqcn.to_string() - } - }; } /// Polymorphic interface for all commands (PHP's `Command` base class as seen by @@ -341,7 +334,7 @@ macro_rules! delegate_command_trait_impls_to_inner { /// the state methods there and override the behavior hooks (`configure`/`execute`/...). /// Object-safe so `dyn Command` works. All methods take `&self`; the command's mutable /// state is interior-mutable (see [`CommandData`]). -pub trait Command: std::fmt::Debug + shirabe_php_shim::AsAny { +pub trait Command: std::fmt::Debug + shirabe_php_shim::AsAny + shirabe_php_shim::PhpClass { /// Configures the current command. fn configure(&self) -> anyhow::Result<()> { Ok(()) @@ -376,12 +369,6 @@ pub trait Command: std::fmt::Debug + shirabe_php_shim::AsAny { Ok(()) } - /// The PHP fully-qualified class name of the concrete command. Port hook for PHP's - /// `\get_class($command)` (used by `CompleteCommand`'s debug log), which Rust cannot - /// reflect from a trait object; every concrete command supplies its FQCN, usually via - /// `delegate_command_trait_impls_to_inner!($field, "Fqcn")`. - fn get_class(&self) -> String; - /// Adds suggestions to `suggestions` for the current completion input. /// /// PHP's `complete` is `void` but can throw; errors are surfaced through `anyhow::Result` @@ -571,15 +558,19 @@ pub trait Command: std::fmt::Debug + shirabe_php_shim::AsAny { fn get_ignore_validation_errors(&self) -> bool; } +impl shirabe_php_shim::PhpClass for CommandData { + fn php_class_name(&self) -> &'static str { + panic!( + "php_class_name called on the base command state; concrete commands supply their class name" + ); + } +} + impl Command for CommandData { fn is_enabled(&self) -> bool { true } - fn get_class(&self) -> String { - panic!("get_class called on the base command state; concrete commands supply their FQCN"); - } - fn set_application( &self, application: Option>>, -- cgit v1.3.1