Beispiel #1
0
 /**
  * Handle request
  */
 public static function handler()
 {
     // Create JSON-RPC request and response.
     $request = static::getRequest();
     $response = static::getResponse();
     // Invoke operation.
     $ex = null;
     try {
         $result = SCA\Domain::run($request->getMethod(), $request->getParams());
         $response->setResult($result);
         // TODO ==>
         if (in_array($result, [null, false, -1], true)) {
             $response->setError(-1);
         }
         // <=======
     } catch (\Exception $ex) {
         // Intentionally fall down.
         $response->setError($ex->getCode());
         error_log((string) $ex);
     }
     // Write response to php output-stream.
     $http = Http\Response::newInstance();
     $http->setBody($response->toJson());
     $http->setHeader('Content-Type', 'application/json-rpc; charset=utf-8');
     $http->send();
     if ($ex instanceof \Exception) {
         throw $ex;
     }
 }
Beispiel #2
0
 /**
  * Delegate operation to the Domain::run method.
  *
  * @param   string  The method name.
  * @param   array   The parameters.
  * @return  mixied  The result.
  */
 public function __call($method, $params)
 {
     $url = implode(SCA\URL::SEPARATOR_METHOD, [$this->url, $method]);
     return SCA\Domain::runArgs($url, $params);
 }