From 5c872cd39802739bfe5e21913b968fe0ae934830 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 17:02:16 +0900 Subject: fix(json-loader): pass decoded config to loader instead of empty map The Phase B stub discarded the decoded PhpMixed and handed an empty IndexMap to LoaderInterface::load, so nothing was actually loaded. Unbox PhpMixed::Array into the map; mirror PHP's array $config type juggling by raising a TypeError for non-array decode results. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe-php-shim/src/lib.rs | 14 ++++++++++++++ crates/shirabe/src/package/loader/json_loader.rs | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'crates') 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 @@ -310,6 +310,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, 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 = 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) } } -- cgit v1.3.1