'DateTime', 'timestamp' => $obj->getTimestamp()); } else if ($obj instanceof RdfObject) { $array = array( self::OBJ_TYPE => $obj->getType(), self::OBJ_UID => $obj->getUid() ); foreach ($obj as $prop => $val) { $array[$prop] = static::marshall($val); } return $array; } else if ($obj instanceof RdfPointer) { return array( self::REF_TYPE => $obj->getType(), self::REF_UID => $obj->getUid() ); } else { return static::marshall((array) $obj); } } public static function unmarshall($obj) { switch (gettype($obj)) { case 'object': $obj = (array) $obj; case 'array': if (static::isWrappedObject($obj)) { return static::unwrapObject($obj); } else if (static::isWrappedReference($obj)) { return static::unwrapReference($obj); } else { return array_map(array('Marshaller', 'unmarshall'), $obj); } default: return $obj; } } private static function unwrapObject($obj) { if (isset($obj[self::OBJ_TYPE])) { $objectType = $obj[self::OBJ_TYPE]; unset($obj[self::OBJ_TYPE]); } if (isset($obj[self::OBJ_UID])) { $objectUid = $obj[self::OBJ_UID]; unset($obj[self::OBJ_UID]); } if ($objectType == 'DateTime') { $date = new DateTime(); $date->setTimestamp($obj['timestamp']); return $date; } else if (is_subclass_of($objectType, 'RdfObject')) { $rdfObject = new $objectType($objectUid); foreach ($obj as $prop => $val) { $rdfObject->$prop = static::unmarshall($val); } return $rdfObject; } else { return $obj; } } private static function unwrapReference($ref) { $refType = $ref[self::REF_TYPE]; $refUid = $ref[self::REF_UID]; return new RdfPointer(RdfObject::typeAndUidToResourceUri($refType, $refUid)); } } ?>