aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-php-shim/src/lib.rs14
-rw-r--r--crates/shirabe/src/package/loader/json_loader.rs17
2 files changed, 28 insertions, 3 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index e87cd2d..9b264e2 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -311,6 +311,20 @@ impl std::fmt::Display for InvalidArgumentException {
impl std::error::Error for InvalidArgumentException {}
#[derive(Debug)]
+pub struct TypeError {
+ pub message: String,
+ pub code: i64,
+}
+
+impl std::fmt::Display for TypeError {
+ fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ todo!()
+ }
+}
+
+impl std::error::Error for TypeError {}
+
+#[derive(Debug)]
pub struct LogicException {
pub message: String,
pub code: i64,
diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs
index 5f8cc4f..fa0e914 100644
--- a/crates/shirabe/src/package/loader/json_loader.rs
+++ b/crates/shirabe/src/package/loader/json_loader.rs
@@ -4,6 +4,8 @@ use crate::json::JsonFile;
use crate::package::PackageInterfaceHandle;
use crate::package::loader::LoaderInterface;
use anyhow::Result;
+use indexmap::IndexMap;
+use shirabe_php_shim::{PhpMixed, TypeError};
use std::path::Path;
pub enum JsonLoaderInput {
@@ -30,8 +32,17 @@ impl JsonLoader {
JsonLoaderInput::String(ref s) => JsonFile::parse_json(Some(s), None)?,
};
- // TODO(phase-b): JsonFile::parse_json returns PhpMixed; loader::load expects IndexMap
- let _ = config;
- self.loader.load(indexmap::IndexMap::new(), None)
+ let config: IndexMap<String, PhpMixed> = match config {
+ PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ _ => {
+ return Err(TypeError {
+ message: "Composer\\Package\\Loader\\LoaderInterface::load(): Argument #1 ($config) must be of type array".to_string(),
+ code: 0,
+ }
+ .into());
+ }
+ };
+
+ self.loader.load(config, None)
}
}