コード例 #1
0
ファイル: Predo.php プロジェクト: raframework/ra
 private static function define(Request $request)
 {
     $requestId = $request->getServerParams()['HTTP_X_REQUEST_ID'];
     if (empty($requestId)) {
         $requestId = Str::uuid();
     }
     define('REQUEST_ID', $requestId);
 }
コード例 #2
0
ファイル: ExceptionHandler.php プロジェクト: raframework/ra
 public static function process(\Exception $e, Request $request, Response $response)
 {
     if ($e instanceof BaseException) {
         $response->withStatus($e->getHttpStatus());
         $response->write(Code::json($e->getCode(), $e->getMessage()));
     } else {
         if ($e instanceof MethodNotAllowedException) {
             $response->withStatus(405);
             $allow = implode(', ', $e->getAllowedMethods());
             $response->withHeader('Allow', $allow);
             $response->write(Code::json(Code::METHOD_NOT_ALLOWED, 'allow: ' . $allow));
         } else {
             if ($e instanceof NotFoundException) {
                 $response->withStatus(404);
                 $response->write(Code::json(Code::RESOURCE_NOT_FOUND));
             } else {
                 if ($e instanceof UnsupportedMediaType) {
                     $response->withStatus(415);
                     $response->write(Code::json(Code::UNSUPPORTED_MEDIA_TYPE, $e->getMessage()));
                 } else {
                     if ($e instanceof BadBodyException) {
                         $response->withStatus(400);
                         $response->write(Code::json(Code::BAD_BODY, $e->getMessage()));
                     } else {
                         if ($e instanceof \PDOException) {
                             $response->withStatus(502);
                             $response->write(Code::json(Code::DATABASE_ERROR));
                             trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                         } else {
                             if ($e instanceof \RedisException) {
                                 $response->withStatus(502);
                                 $response->write(Code::json(Code::CACHE_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             } else {
                                 $response->withStatus(500);
                                 $response->write(Code::json(Code::INTERNAL_SERVER_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: raframework/ra
 private function parsePdoName($pdoName)
 {
     return Str::endsWith($pdoName, ['::read', '::write']) ? explode('::', $pdoName, 2) : [$pdoName, null];
 }
コード例 #4
0
ファイル: Redis.php プロジェクト: raframework/ra
 /**
  * Dynamically pass methods to the redis
  *
  * @param  string $method
  * @param  array  $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     Log::debug('redis ' . $method . ' parameters: ' . json_encode($parameters));
     $queryType = 'master';
     // TODO: determines by operation
     if (!$this->link($queryType)) {
         return false;
     }
     try {
         Time::start('redis');
         $result = call_user_func_array([$this->link, $method], $parameters);
         Time::stop('redis');
         Log::debug('redis ' . $method . ' result: ' . $result);
     } catch (\Exception $e) {
         trigger_error('Errors on operating redis: ' . Str::exceptionToString($e), E_USER_WARNING);
         return false;
     }
     return $result;
 }