diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-08 01:54:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-08 01:54:56 +0900 |
| commit | 318ea948f5932dfa7942081a269d62fd7161a9bf (patch) | |
| tree | 0fff2fe818f87a20dea89a51901f9e16071f2f53 /crates/shirabe/src/repository/vcs/mod.rs | |
| parent | f232d7f9d2936ef84bd904cacd21c12cb7012b34 (diff) | |
| download | php-shirabe-318ea948f5932dfa7942081a269d62fd7161a9bf.tar.gz php-shirabe-318ea948f5932dfa7942081a269d62fd7161a9bf.tar.zst php-shirabe-318ea948f5932dfa7942081a269d62fd7161a9bf.zip | |
feat(phase-c): resolve reflection/downcast phase-b TODOs
Resolve category F phase-b TODOs (class-string, instanceof, get_class,
method_exists, __FILE__, Reflection API, downcast).
- VcsRepository: dispatch drivers through a VcsDriverKind enum
(instantiate/supports/php_class_name) and add constructors to the
concrete VCS drivers
- repository downcasts via RepositoryInterfaceHandle::downcast_rc and
as_any (init/show commands, vcs ValidatingArrayLoader)
- BaseCommand::is_self_update_command override replaces an instanceof
- Factory::create narrows PartialComposer to ComposerHandle via as_full
- InstalledVersions gains set_self_dir/set_installed_is_local_dir,
replacing Reflection-based static property mutation
- ClassLoader::as_array_iter ports the PHP (array) cast
- drop the unnecessary __FILE__ phar branch in self-update
application get_class(command) reclassified TODO(plugin); buffer_io
StreamableInputInterface downcast and the ValidatingArrayLoader trait
redesign left as tracked TODOs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository/vcs/mod.rs')
| -rw-r--r-- | crates/shirabe/src/repository/vcs/mod.rs | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/crates/shirabe/src/repository/vcs/mod.rs b/crates/shirabe/src/repository/vcs/mod.rs index 715d2e5..5c60e0a 100644 --- a/crates/shirabe/src/repository/vcs/mod.rs +++ b/crates/shirabe/src/repository/vcs/mod.rs @@ -21,3 +21,134 @@ pub use perforce_driver::*; pub use svn_driver::*; pub use vcs_driver::*; pub use vcs_driver_interface::*; + +use crate::config::Config; +use crate::io::IOInterface; +use crate::util::{HttpDownloader, ProcessExecutor}; +use indexmap::IndexMap; +use shirabe_php_shim::PhpMixed; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum VcsDriverKind { + GitHub, + GitLab, + GitBitbucket, + Forgejo, + Git, + Hg, + Perforce, + Fossil, + Svn, +} + +impl VcsDriverKind { + pub fn instantiate( + self, + repo_config: IndexMap<String, PhpMixed>, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: std::rc::Rc<std::cell::RefCell<Config>>, + http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>, + process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>, + ) -> Box<dyn VcsDriverInterface> { + match self { + VcsDriverKind::GitHub => Box::new(GitHubDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::GitLab => Box::new(GitLabDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::GitBitbucket => Box::new(GitBitbucketDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Forgejo => Box::new(ForgejoDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Git => Box::new(GitDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Hg => Box::new(HgDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Perforce => Box::new(PerforceDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Fossil => Box::new(FossilDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + VcsDriverKind::Svn => Box::new(SvnDriver::new( + repo_config, + io, + config, + http_downloader, + process, + )), + } + } + + pub fn supports( + self, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: std::rc::Rc<std::cell::RefCell<Config>>, + url: &str, + deep: bool, + ) -> anyhow::Result<bool> { + match self { + VcsDriverKind::GitHub => GitHubDriver::supports(io, config, url, deep), + VcsDriverKind::GitLab => GitLabDriver::supports(io, config, url, deep), + VcsDriverKind::GitBitbucket => GitBitbucketDriver::supports(io, config, url, deep), + VcsDriverKind::Forgejo => ForgejoDriver::supports(io, config, url, deep), + VcsDriverKind::Git => GitDriver::supports(io, config, url, deep), + VcsDriverKind::Hg => HgDriver::supports(io, config, url, deep), + VcsDriverKind::Perforce => PerforceDriver::supports(io, config, url, deep), + VcsDriverKind::Fossil => FossilDriver::supports(io, config, url, deep), + 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 { + 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", + } + } +} |
