Пример #1
0
 /**
  * Execute JSON-RPC Request
  *
  * @param string $method
  * @param array $params
  * @return array
  */
 public function call($method, $params = null)
 {
     $this->clear();
     $request = array('jsonrpc' => '2.0', 'id' => 'a' . uniqid('', true), 'method' => $method);
     if (isset($params)) {
         $request['params'] = $params;
     }
     $json = $this->encoder->encode($request);
     $response = $this->post($json);
     $this->response = $this->encoder->decode($response);
     return $this->response;
 }
Пример #2
0
 /**
  * Send value as json string
  *
  * @param array $data
  * @return boolean
  */
 protected function setJsonContent($data)
 {
     $this->response->prepare($this->request);
     // Send Json response header
     if (!headers_sent()) {
         $this->response->headers->set('Content-Type', 'application/json');
         $this->response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
         $this->response->headers->set('Pragma', 'no-cache');
         $this->response->headers->set('Expires', '0');
         $encoding = $this->request->server->get('HTTP_ACCEPT_ENCODING');
         if (isset($encoding) && strpos($encoding, 'gzip') !== false) {
             ob_start('ob_gzhandler');
             $this->response->headers->set('Content-Encoding', 'gzip');
         }
     }
     $this->response->setContent($this->encoder->encode($data));
     return true;
 }