public function __get($field_name) { //echo ("__get:$field_name"); $res = myBaseObject::envokeMethod($this->m_obj, $field_name); if ($this->m_recursive_wrapping) { // wrap non-primative properties if (is_object($res) || is_array($res)) { $res = new genericObjectWrapper($res); } } if ($res == null && $this->m_ignore_null) { return genericNullWrapper::getInstance(); } return $res; }
public function __get($field_name) { // echo ("__get:$field_name<br>"); // before envoking the method - something that can cause a hit to the DB - // check if object is in object cache $res = self::$use_cache ? $this->fetchFromCache($field_name) : null; $from_cache = false; if ($res == null) { try { $res = myBaseObject::envokeMethod($this->m_obj, $field_name); } catch (Exception $ex) { $res = "Error{$field_name}"; } } else { $from_cache = true; } if ($this->m_recursive_wrapping) { // wrap non-primative properties if (is_object($res)) { $val = self::getWrapperClass($res, $this->detail_level, $this->detail_policy_velocity, $this->recursion_depth); if (self::$use_cache && !$from_cache) { // echo "putting object in cache $field_name, [" . get_class ( $val ) . "]\n"; if ($val) { $this->putInCache($field_name, $val->getWrappedObj()); } } return $val; } else { if (is_array($res)) { list($val, $original_arr) = self::getWrapperClass($res, $this->detail_level, $this->detail_policy_velocity, $this->recursion_depth); if (self::$use_cache && !$from_cache) { // echo "putting in array cache $field_name, [" . get_class ( $val ) . "]\n"; if ($val) { $this->putInCache($field_name, $original_arr); } } return $val; } } return $res; } else { return $res; } }
/** * param_names is the list of fields to add as attributes to the xml node. * each element in the array can either be a field name or a pair of name=>alias. * if name - the name will be used as the attribute name. * if name=>alias - the 'alias' will be used as the attribute name instead. */ public static function objToXml(BaseObject $obj, array $param_names, $xml_element_name = NULL, $close_xml_element = true, $map_to_add = NULL, $envoke_method = false) { if ($obj == NULL) { return NULL; } if (!$obj instanceof BaseObject) { throw new Exception("objToXml should have the first parameter an object of type BaseObject"); } $res = $xml_element_name == NULL ? "" : "<" . $xml_element_name . " "; foreach ($param_names as $param_name => $param_alias) { // this is to be compatible both for flat arrays & associative ones // it ASSUMEs there are no fields that are numbers in a BaseObject $name = is_numeric($param_name) ? $param_alias : $param_name; if ($envoke_method) { // $raw_value = myBaseObject::envokeMethod($obj, $name); } else { $raw_value = $obj->getByName($name, BasePeer::TYPE_FIELDNAME); } // escape the value of the attribute $value = kString::xmlEncode($raw_value); $res .= ' ' . $param_alias . '="' . $value . '"'; } if ($map_to_add != NULL) { foreach ($map_to_add as $attr => $val) { $res .= ' ' . $attr . '="' . kString::xmlEncode($val) . '"'; } } $res .= $xml_element_name == NULL ? "" : $close_xml_element ? "/>\n" : ">\n"; return $res; }