diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-02 16:16:51 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-02 16:16:51 +0900 |
| commit | 6047bcc3e63ab84dfc67bce94f402f1bfa3f58d5 (patch) | |
| tree | e0fc935abf0cebb2c557581fbfd098bdef35d558 /crates/shirabe/src/repository | |
| parent | 4361059d3bb27916179acfebb8889f1863319bb9 (diff) | |
| download | php-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/src/repository')
| -rw-r--r-- | crates/shirabe/src/repository/vcs.rs | 26 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs_repository.rs | 2 |
2 files changed, 15 insertions, 13 deletions
diff --git a/crates/shirabe/src/repository/vcs.rs b/crates/shirabe/src/repository/vcs.rs index 5c60e0a9..920fefa3 100644 --- a/crates/shirabe/src/repository/vcs.rs +++ b/crates/shirabe/src/repository/vcs.rs @@ -26,7 +26,7 @@ use crate::config::Config; use crate::io::IOInterface; use crate::util::{HttpDownloader, ProcessExecutor}; use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; +use shirabe_php_shim::{PhpClass, PhpMixed}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum VcsDriverKind { @@ -136,19 +136,21 @@ impl VcsDriverKind { VcsDriverKind::Svn => SvnDriver::supports(io, config, url, deep), } } +} - /// PHP fully-qualified `class-string`, used as the fallback driver name in `getRepoName()`. - pub fn php_class_name(self) -> &'static str { +impl PhpClass for VcsDriverKind { + /// Used as the fallback driver name in `getRepoName()`. + fn php_class_name(&self) -> &'static str { match self { - VcsDriverKind::GitHub => "Composer\\Repository\\Vcs\\GitHubDriver", - VcsDriverKind::GitLab => "Composer\\Repository\\Vcs\\GitLabDriver", - VcsDriverKind::GitBitbucket => "Composer\\Repository\\Vcs\\GitBitbucketDriver", - VcsDriverKind::Forgejo => "Composer\\Repository\\Vcs\\ForgejoDriver", - VcsDriverKind::Git => "Composer\\Repository\\Vcs\\GitDriver", - VcsDriverKind::Hg => "Composer\\Repository\\Vcs\\HgDriver", - VcsDriverKind::Perforce => "Composer\\Repository\\Vcs\\PerforceDriver", - VcsDriverKind::Fossil => "Composer\\Repository\\Vcs\\FossilDriver", - VcsDriverKind::Svn => "Composer\\Repository\\Vcs\\SvnDriver", + VcsDriverKind::GitHub => r"Composer\Repository\Vcs\GitHubDriver", + VcsDriverKind::GitLab => r"Composer\Repository\Vcs\GitLabDriver", + VcsDriverKind::GitBitbucket => r"Composer\Repository\Vcs\GitBitbucketDriver", + VcsDriverKind::Forgejo => r"Composer\Repository\Vcs\ForgejoDriver", + VcsDriverKind::Git => r"Composer\Repository\Vcs\GitDriver", + VcsDriverKind::Hg => r"Composer\Repository\Vcs\HgDriver", + VcsDriverKind::Perforce => r"Composer\Repository\Vcs\PerforceDriver", + VcsDriverKind::Fossil => r"Composer\Repository\Vcs\FossilDriver", + VcsDriverKind::Svn => r"Composer\Repository\Vcs\SvnDriver", } } } diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index b7ce1a6c..9b1b0d84 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -29,7 +29,7 @@ use crate::util::Url; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ - InvalidArgumentException, PhpMixed, in_array, php_regex, str_replace, strpos, + InvalidArgumentException, PhpClass, PhpMixed, in_array, php_regex, str_replace, strpos, }; use shirabe_semver::constraint::SimpleConstraint; |
