aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 16:16:51 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 16:16:51 +0900
commit6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5 (patch)
treee0fc935abf0cebb2c557581fbfd098bdef35d558 /crates/shirabe-php-shim/src
parent4361059d3bb27916179acfebb8889f1863319bb9 (diff)
downloadphp-shirabe-6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5.tar.gz
php-shirabe-6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5.tar.zst
php-shirabe-6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src')
-rw-r--r--crates/shirabe-php-shim/src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index 93b2e430..ab904a46 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -284,6 +284,33 @@ impl<T: std::any::Any> AsAny for T {
}
}
+/// A ported type that reports the name of the PHP class it was ported from.
+///
+/// Rust has no runtime class name, so the PHP class name is stated once at the type's
+/// definition through [`impl_php_class!`]. Implement this wherever the port needs what PHP's
+/// `\get_class()` would report.
+pub trait PhpClass {
+ /// The fully-qualified class name, e.g. `Composer\Command\InstallCommand`.
+ fn php_class_name(&self) -> &'static str;
+}
+
+/// Implements [`PhpClass`] for a ported type, given the fully-qualified name of the PHP
+/// class it was ported from.
+///
+/// ```ignore
+/// impl_php_class!(InstallCommand, r"Composer\Command\InstallCommand");
+/// ```
+#[macro_export]
+macro_rules! impl_php_class {
+ ($ty:ty, $class_name:literal) => {
+ impl $crate::PhpClass for $ty {
+ fn php_class_name(&self) -> &'static str {
+ $class_name
+ }
+ }
+ };
+}
+
impl From<i64> for PhpMixed {
fn from(value: i64) -> Self {
PhpMixed::Int(value)