Example #1
0
 public function handle(IServerRequest $request)
 {
     $doc = MimedDocument::createText('test');
     $uri = Uri::createFromString('/test');
     switch ($request->getQueryParams()['r']) {
         case 'ok':
             return $this->responseOk($doc);
             break;
         case 'bad_request':
             return $this->responseBadRequest($doc);
             break;
         case 'forbidden':
             return $this->responseForbidden($doc);
             break;
         case 'not_found':
             return $this->responseNotFound($doc);
             break;
         case 'redirect_perm':
             return $this->redirect($uri, true);
             break;
         case 'redirect_temp':
             return $this->redirect($uri, false);
             break;
         case 'error':
             return $this->responseError($doc);
             break;
         default:
             throw new \LogicException('Undefined');
             break;
     }
 }
Example #2
0
 private function routeAndHandleRequest(IServerRequest $request)
 {
     $route_point = $this->router->route($request->getUri()->getPath());
     $handler = $this->handlers->getHandler($route_point->path());
     $response = $handler->handle($request->withJoinedQueryParams($route_point->arguments()));
     return $response;
 }
Example #3
0
 public function resume(IServerRequest $request)
 {
     if ($this->isActive()) {
         return true;
     }
     $cookies = $request->getCookieParams();
     if (!array_key_exists(session_name(), $cookies)) {
         return false;
     }
     if (!session_start()) {
         throw new \RuntimeException('Can not resume session');
     }
     $inner_storage = $this->getInnerStorage();
     if (!$inner_storage->has('started_at')) {
         $this->stop();
         return false;
     }
     return true;
 }