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; } }
public function toString() { $str = ""; $field_added = false; foreach ($this->fields as $field => $name) { // echo $field . "=" . $this->fields[$field] . "<br>"; if ($field_added) { // for the second time onwards ... $str .= "<br>"; // for nice display } $str .= $field . myBaseObject::FIELD_EQUAL . myBaseObject::encode($this->fields[$field]); $field_added = true; } return $str; }
public function fillObjectFromXml(SimpleXMLElement $simple_xml_node, $prefix_to_add, $exclude_params = null) { if (!is_array($exclude_params)) { $exclude_params = array(); } $exclude_params[] = 'advancedSearch'; $set_field_count = parent::fillObjectFromXml($simple_xml_node, $prefix_to_add, $exclude_params); if (isset($simple_xml_node->advancedSearch)) { $attr = $simple_xml_node->advancedSearch->attributes(); if (isset($attr['type']) && class_exists($attr['type'])) { $type = (string) $attr['type']; KalturaLog::debug("Advanced Search type[{$type}] and value[" . $simple_xml_node->advancedSearch->asXML() . "]"); $this->advancedSearch = new $type(); $this->advancedSearch->fillObjectFromXml($simple_xml_node->advancedSearch); } $set_field_count++; } return $set_field_count; }
/** * 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; }