aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/repository_manager.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/repository/repository_manager.rs')
-rw-r--r--crates/shirabe/src/repository/repository_manager.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/crates/shirabe/src/repository/repository_manager.rs b/crates/shirabe/src/repository/repository_manager.rs
index 403b504..247236c 100644
--- a/crates/shirabe/src/repository/repository_manager.rs
+++ b/crates/shirabe/src/repository/repository_manager.rs
@@ -147,10 +147,30 @@ impl RepositoryManager {
fn create_repository_by_class(
&self,
- _class: &str,
- _config: IndexMap<String, PhpMixed>,
+ class: &str,
+ config: IndexMap<String, PhpMixed>,
) -> anyhow::Result<RepositoryInterfaceHandle> {
- todo!("Phase B: dynamic class instantiation by class name")
+ // PHP: `new $class($config, $this->io, $this->config, $this->httpDownloader,
+ // $this->eventDispatcher, $this->process)`. Rust cannot instantiate by string class name, so
+ // dispatch over the classes registered in `createDefaultRepositoryManager`.
+ match class {
+ "Composer\\Repository\\ComposerRepository" => Ok(RepositoryInterfaceHandle::new(
+ crate::repository::ComposerRepository::new(
+ config,
+ self.io.clone(),
+ &self.config.borrow(),
+ self.http_downloader.clone(),
+ self.event_dispatcher.clone(),
+ )?,
+ )),
+ "Composer\\Repository\\PackageRepository" => Ok(RepositoryInterfaceHandle::new(
+ crate::repository::PackageRepository::new(config),
+ )),
+ other => todo!(
+ "Phase B: dynamic class instantiation by class name: {}",
+ other
+ ),
+ }
}
pub fn set_repository_class(&mut self, r#type: &str, class: &str) {