From a3171eefd8f8e520329bdd8f613e83ba6f0a7c13 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 18:49:24 +0900 Subject: refactor(php-shim): remove ArrayObject, inline IndexMap into PhpMixed::Object ArrayObject was only a thin wrapper around IndexMap used as an empty-{} vs empty-[] marker and as the assoc=false JSON object representation; no reference semantics were involved. Inline its payload directly into PhpMixed::Object and drop the type along with the now-dead StdClass. Side effects of the unification: - ArrayObject::new was todo!(); the config --global / object-typed get paths that built PhpMixed::Object(ArrayObject::new(None)) no longer panic. - base_config_command wrote 'config' as PhpMixed::Array(empty), emitting [] instead of {}; now matches PHP's new \ArrayObject ({}). - The dead is::()/is::() instanceof checks in JsonManipulator are replaced with the faithful as_object() mapping. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 69 +++++++++----------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) (limited to 'crates/shirabe-php-shim/src/lib.rs') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index b42ed75..0d7f8ef 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -62,7 +62,8 @@ pub enum PhpMixed { String(String), List(Vec), Array(IndexMap), - Object(ArrayObject), + // TODO: consolidate Object to Array. + Object(IndexMap), } impl serde::Serialize for PhpMixed { @@ -91,7 +92,13 @@ impl serde::Serialize for PhpMixed { } map.end() } - PhpMixed::Object(object) => object.serialize(serializer), + PhpMixed::Object(entries) => { + let mut map = serializer.serialize_map(Some(entries.len()))?; + for (k, v) in entries { + map.serialize_entry(k, v)?; + } + map.end() + } } } } @@ -112,37 +119,17 @@ impl PartialEq for PhpMixed { .zip(b.iter()) .all(|((ka, va), (kb, vb))| ka == kb && va == vb) } - (PhpMixed::Object(a), PhpMixed::Object(b)) => a == b, + (PhpMixed::Object(a), PhpMixed::Object(b)) => { + a.len() == b.len() + && a.iter() + .zip(b.iter()) + .all(|((ka, va), (kb, vb))| ka == kb && va == vb) + } _ => false, } } } -impl PartialEq for ArrayObject { - fn eq(&self, other: &Self) -> bool { - self.data.len() == other.data.len() - && self - .data - .iter() - .zip(other.data.iter()) - .all(|((ka, va), (kb, vb))| ka == kb && va == vb) - } -} - -impl serde::Serialize for ArrayObject { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - use serde::ser::SerializeMap; - let mut map = serializer.serialize_map(Some(self.data.len()))?; - for (k, v) in &self.data { - map.serialize_entry(k, v)?; - } - map.end() - } -} - impl PhpMixed { pub fn as_bool(&self) -> Option { match self { @@ -200,7 +187,7 @@ impl PhpMixed { } } - pub fn as_object(&self) -> Option<&ArrayObject> { + pub fn as_object(&self) -> Option<&IndexMap> { match self { PhpMixed::Object(o) => Some(o), _ => None, @@ -351,30 +338,6 @@ impl std::fmt::Display for PhpMixed { } } -#[derive(Debug, Clone)] -pub struct ArrayObject { - data: IndexMap, -} - -impl ArrayObject { - pub fn new(_array: Option) -> Self { - todo!() - } - - pub fn to_array(&self) -> IndexMap { - self.data.clone() - } - - pub fn count(&self) -> usize { - self.data.len() - } -} - -#[derive(Debug)] -pub struct StdClass { - pub data: IndexMap, -} - #[derive(Debug, Clone)] pub enum PhpResource { Stdin, -- cgit v1.3.1