From 318ea948f5932dfa7942081a269d62fd7161a9bf Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 8 Jun 2026 01:54:56 +0900 Subject: 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) --- crates/shirabe/src/repository/handle.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/shirabe/src/repository/handle.rs') diff --git a/crates/shirabe/src/repository/handle.rs b/crates/shirabe/src/repository/handle.rs index 0d02b83..aa79d5e 100644 --- a/crates/shirabe/src/repository/handle.rs +++ b/crates/shirabe/src/repository/handle.rs @@ -66,6 +66,24 @@ impl RepositoryInterfaceHandle { self.0.borrow().as_any().is::() } + /// Downcasts the shared handle to a concrete repository type, preserving shared ownership. + pub fn downcast_rc(&self) -> Option>> { + if self.0.borrow().as_any().is::() { + let rc = self.0.clone(); + let ptr = Rc::into_raw(rc) as *const RefCell; + // SAFETY: is::() proved the value is `T`, and handles are always allocated as + // `Rc::new(RefCell::new(concrete))`, so the layout matches `RcBox>`. + Some(unsafe { Rc::from_raw(ptr) }) + } else { + None + } + } + + pub fn as_platform_repository(&self) -> Option { + self.downcast_rc::() + .map(PlatformRepositoryHandle::from_rc) + } + pub fn count(&self) -> i64 { self.0.borrow().count() } -- cgit v1.3.1