updateFromSaveableObj($saveableObject); } public function __set($attr,$value){ if (strcmp($attr,"id")==0 || strcmp($attr,"_id")==0){ if (strcmp($attr,"id")==0){ $attr = "_id"; } if (!($value instanceof MongoId)){ $value = new MongoId($value); } } $this->saveableObject->$attr = $value; } public function &__get($attr){ $rval = null; if (strcmp($attr,"id")==0 || strcmp($attr,"_id")==0){ if (strcmp($attr,"id")==0){ $attr = "_id"; } if ($this->hasProperty($attr)){ $idf = '$id'; $rval = &$this->saveableObject->$attr->$idf; } else { $rval = null; } } else { $rval = &$this->saveableObject->$attr; } return $rval; } public function __unset($attr){ unset($this->saveableObject->$attr); } public function hasProperty($attr){ if (strcmp($attr,"id")==0){ $attr = "_id"; } return property_exists($this->saveableObject, $attr); } /** * (non-PHPdoc) * @see DaoSaveable::getSaveableObj() */ public function getSaveableObj(){ // return $this->saveableObject; return $this->toArray($this->saveableObject); } private function toArray($input){ $rval = $input; if (is_object($rval) ){ if (!($rval instanceof MongoId)){ $rval = (array)$input; } // $rval = (array)$input; } if (is_array($rval)) { foreach ( $rval as $key=>$val){ $rval[$key] = $this->toArray($val); } } return $rval; } /** * (non-PHPdoc) * @see DaoSaveable::buildFromSaveableObj() */ public static function buildFromSaveableObj($saveableObject){ return new static($saveableObject); } /** * (non-PHPdoc) * @see DaoSaveable::updateFromSaveableObj() */ public function updateFromSaveableObj($saveableObject){ $this->saveableObject = $this->toObject($saveableObject); if (!property_exists($this->saveableObject, "deleted")){ $this->saveableObject->deleted = false; } // $this->saveableObject = $saveableObject; } private function toObject($input){ $rval = $input; if (is_array($input) && sizeof(array_diff_key($input,array_keys($input)))>0 ){ $rval = (object)$input; } if (is_array($rval)){ foreach ( $rval as $key=>$val){ $rval[$key] = $this->toObject($val); } } else if (is_object($rval)) { if (!($rval instanceof MongoId)){ foreach ( $rval as $key=>$val){ $rval->$key = $this->toObject($val); } } } return $rval; } } ?>