public function success($response) { $pq = PhpQuery::newDocument($response); foreach ($this->calls as $k => $r) { // check if method exists if (!method_exists(get_class($pq), $r['method'])) { throw new \Exception("Method '{$r['method']}' not implemented in PhpQuery, sorry..."); // execute method } else { $pq = call_user_func_array(array($pq, $r['method']), $r['arguments']); } } if (!isset($this->options['dataType'])) { $this->options['dataType'] = ''; } switch (strtolower($this->options['dataType'])) { case 'json': if ($pq instanceof PhpQueryObject) { $results = array(); foreach ($pq as $node) { $results[] = pq($node)->htmlOuter(); } print PhpQuery::toJSON($results); } else { print PhpQuery::toJSON($pq); } break; default: print $pq; } // output results }