Пример #1
0
 protected function exec(Request $request, Response $response)
 {
     $route = $this->dispatch($request);
     $request->setRoute($route);
     $action = $this->createAction($route);
     // 中止继续访问
     if ($request->abort == true) {
         return;
     }
     $request->callMiddleware();
     $response->setPrefix($route->getPrefix());
     Hook::fire("action_pre", [$request, $response]);
     $data = $this->runAction($action, $request, $response);
     if (!$data instanceof Response && $data !== null) {
         $response->with($data);
     }
 }
Пример #2
0
 protected function report($exception)
 {
     if (in_array(get_class($exception), $this->notReport)) {
         return;
     }
     $errorLevelMap = [E_ERROR => LogLevel::CRITICAL, E_WARNING => LogLevel::WARNING, E_PARSE => LogLevel::ALERT, E_NOTICE => LogLevel::NOTICE, E_CORE_ERROR => LogLevel::CRITICAL, E_CORE_WARNING => LogLevel::WARNING, E_COMPILE_ERROR => LogLevel::ALERT, E_COMPILE_WARNING => LogLevel::WARNING, E_USER_ERROR => LogLevel::ERROR, E_USER_WARNING => LogLevel::WARNING, E_USER_NOTICE => LogLevel::NOTICE, E_STRICT => LogLevel::NOTICE, E_RECOVERABLE_ERROR => LogLevel::ERROR, E_DEPRECATED => LogLevel::NOTICE, E_USER_DEPRECATED => LogLevel::NOTICE];
     $context = !CLI_MODE ? request()->server : [];
     if ($exception instanceof ErrorException) {
         $level = $errorLevelMap[$exception->getCode()];
         $message = "ErrorException '" . get_class($exception) . "' with message '{$exception->getMessage()}' in " . $exception->getFile() . ':' . $exception->getLine();
         \Kerisy\Core\Hook::fire("exception_report", [$level, $message]);
         $this->logger->log($level, $message, $context);
     } else {
         if ($exception instanceof \Exception) {
             $message = "Exception '" . get_class($exception) . "' with message '{$exception->getMessage()}' in " . $exception->getFile() . ':' . $exception->getLine();
             $level = isset($errorLevelMap[$exception->getCode()]) ? $errorLevelMap[$exception->getCode()] : "error";
             \Kerisy\Core\Hook::fire("exception_report", [$level, $message]);
             $this->logger->error($message, $context);
         } else {
             $this->logger->error($exception, $context);
         }
     }
 }
Пример #3
0
 /**
  * 接收
  *
  * @param $serv
  * @param $fd
  * @param $from_id
  * @param $data
  */
 public function onReceive($serv, $fd, $from_id, $data)
 {
     Hook::fire("monitor_receive", [$fd, $from_id, $data]);
 }
Пример #4
0
 public function onRequest($request, $response)
 {
     Hook::fire("server_start");
     $res = $this->handleRequest($this->prepareRequest($request));
     $content = $res->content();
     foreach ($res->headers->all() as $name => $values) {
         $name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $name)));
         foreach ($values as $value) {
             $response->header($name, $value);
         }
     }
     $response->header('Content-Length', strlen($content));
     if ($res->getCookies()) {
         foreach ($res->getCookies() as list($key, $value, $ttl, $path, $domain, $secure, $httponly)) {
             $response->cookie($key, $value, $ttl, $path = '/', $domain, $secure, $httponly);
         }
     }
     $response->status($res->statusCode);
     Hook::fire("server_end", [$request, $response]);
     $response->end($content);
 }