apiRequest = $request; } public function getService() { return $this->getRequestParameter('service', Api_Kwick_Request::DEFAULT_SERVICE); } public function getMethod() { return $this->getRequestParameter('method', Api_Kwick_Request::DEFAULT_METHOD); } public function getSecret() { return $this->getRequestParameter('secret'); } public function getRequestParameter($name, $default = null) { $parameter = $default; if (isset($_GET[$name]) && !empty($_GET[$name])) { $parameter = $_GET[$name]; } if (isset($_POST[$name]) && !empty($_POST[$name])) { $parameter = $_POST[$name]; } return $parameter; } public function prepareParametersOnRequest() { foreach (array($_GET, $_POST) as $params) { foreach ($params as $name => $value) { if (in_array($name, array('service', 'method', 'secret')) || empty($value)) { continue; } $this->apiRequest->setParameter($name, $value); } } } public function dispatch() { Api_Log::log('Dispatching ' . $this->getService() . '.' . $this->getMethod()); $this->apiRequest->setService($this->getService()); $this->apiRequest->setMethod($this->getMethod()); $secret = $this->getSecret(); if (null !== $secret) { Api_Log::log('Setting user secret: ' . $secret); $this->apiRequest->setSecret($secret); } $this->prepareParametersOnRequest(); try { $data = array('response' => json_decode($this->apiRequest->send())); } catch (Exception $e) { $data = array('exception' => $e->__toString()); } $data['log'] = Api_Log::get(); // echo str_replace('\\', '\\\\', json_encode($data)); echo json_encode($data); } }