#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PhpKey {
Int(i64),
Str(Vec<u8>),
}
#[derive(Debug, Clone)]
pub enum PhpValue {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(Vec<u8>),
Array(Vec<(PhpKey, PhpValue)>),
Object {
class: String,
properties: Vec<(PhpKey, PhpValue)>,
},
Custom {
class: String,
data: Vec<u8>,
},
Enum {
class: String,
case: String,
},
Ref(u32),
ObjectRef(u32),
}
impl PartialEq for PhpValue {
fn eq(&self, other: &Self) -> bool {
use PhpValue::*;
match (self, other) {
(Null, Null) => true,
(Bool(a), Bool(b)) => a == b,
(Int(a), Int(b)) => a == b,
(Float(a), Float(b)) => a.to_bits() == b.to_bits(),
(Str(a), Str(b)) => a == b,
(Array(a), Array(b)) => a == b,
(
Object {
class: c1,
properties: p1,
},
Object {
class: c2,
properties: p2,
},
) => c1 == c2 && p1 == p2,
(
Custom {
class: c1,
data: d1,
},
Custom {
class: c2,
data: d2,
},
) => c1 == c2 && d1 == d2,
(
Enum {
class: c1,
case: k1,
},
Enum {
class: c2,
case: k2,
},
) => c1 == c2 && k1 == k2,
(Ref(a), Ref(b)) => a == b,
(ObjectRef(a), ObjectRef(b)) => a == b,
_ => false,
}
}
}
impl PhpValue {
pub fn contains_object(&self) -> bool {
match self {
PhpValue::Object { .. }
| PhpValue::Custom { .. }
| PhpValue::Enum { .. }
| PhpValue::ObjectRef(_) => true,
PhpValue::Array(items) => items.iter().any(|(_, v)| v.contains_object()),
_ => false,
}
}
}