OperationRequest); $this->result = (array) $result; $this->buffer = array(); $this->toArray($this->result); } /* public function parse($operation, &$paths, $base = '') { if($operation == 'ItemLookup') return itemLookupParse($paths, $base); } */ /** * Extracts a particular element from result * * $paths is an array of arrays where each element is * of the form array('key' => '', 'path' => '', 'callback' => '') * key is the index of the array the data will be stored in * path is a comma separated list or array of indicies where * the last index is the target element * callback (optional) is the function that will be applied * to the target. ex $target = callback($target) */ public function parse(&$paths, $base = '') { $data = array(); for($i = 0; $i < count($paths); $i++) { $path = $paths[$i]['path']; $key = $paths[$i]['key']; $callback = isset($paths[$i]['callback']) ? $paths[$i]['callback'] : null; if(!is_array($path)) $path = explode(',', $path); if($base != '' && count($base) > 0) { if(!is_array($base)) $base = explode(',', $base); $path = array_merge($base, $path); } $this->fetch($path, $this->result, $callback); if(count($this->buffer) > 1) $data[$key] = $this->buffer; elseif(count($this->buffer) == 1) $data[$key] = $this->buffer[0]; else $data[$key] = null; $this->buffer = array(); } return $data; } private function fetch(&$path, &$data, $callback) { $curr = array_shift($path); //if there are multiple instances if(isset($data[1])) { for($i = 0; $i < count($data); $i++) { $this->fetch($path, $data[$i], $callback); } } //if this is the last node in the path elseif(count($path) == 0) { if($callback != '' && function_exists($callback)) $this->buffer[] = $callback($data[$curr]); else $this->buffer[] = $data[$curr]; } //move on to the next node else { if(isset($data[$curr])) $this->fetch($path, $data[$curr], $callback); else return; //dead end } } private function toArray(&$data = null) { if($data === null) $data = &$this->result; foreach($data as $key => $value) { if(!is_array($data[$key]) && is_object($data[$key])) $data[$key] = (array) $value; if(is_array($data[$key])) $this->toArray($data[$key]); } } } ?>