function __parse_block_into_array () { $hash = array(); while ($this->__index < count($this->__elements)) { $element = &$this->__elements[$this->__index]; $this->__index++; $key = Inflector::underscore($element['tag']); $attributes = array(); if (isset($element['attributes'])) { foreach ($element['attributes'] as $k => $v) $attributes[strtolower($k)] = $v; } $value = null; switch($element['type']) { case 'open': $value = $this->__parse_block_into_array(); break; case 'complete': $value = isset($element['value']) ? $element['value'] : ''; if (isset($attributes['encoding']) && $attributes['encoding'] == 'base64') $value = base64_decode($value); break; case 'close': return $hash; default: // ignore other element types } if (!is_null($value)) { if (isset($hash[$key])) { if (!is_array($hash[$key]) || ArrayHelper::is_associative($hash[$key])) $hash[$key] = array($hash[$key], $value); else array_push($hash[$key], $value); } else $hash[$key] = $value; } } return $hash; }
function __find_all ($class) { $query_string = ""; if (count($class->attributes) > 0) $query_string = "?" . join('&', array_map(create_function('$a,$b', 'return "$a=$b";'), array_keys($class->attributes), array_values($class->attributes))); $response = $this->__request($class, 'GET', $query_string); $parser = new XMLParser(); $array = $parser->parse_into_array($response->body); $class_name = "SS" . $class->class_name(); $singular = Inflector::underscore($class->class_name()); $plural = Inflector::pluralize($singular); $records = $array[$plural][$singular]; if (ArrayHelper::is_associative($records)) $records = array($records); $objects = array(); foreach ($records as $attrs) $objects[] = new $class_name($attrs); return $objects; }