Ejemplo n.º 1
0
 /**
  * @param WebRequest $request
  * @return \watoki\curir\delivery\WebResponse
  */
 public function createResponse(WebRequest $request)
 {
     $response = new WebResponse();
     $response->setStatus($this->status);
     $response->getHeaders()->set(WebResponse::HEADER_LOCATION, $this->getAbsoluteTarget($request)->toString());
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * @param \watoki\collections\Liste $formats
  * @throws HttpError If no renderer for accepted format and no default renderer is set
  * @return WebResponse
  */
 private function respondWithDefault(Liste $formats)
 {
     if (!isset($this->renderers[''])) {
         throw new HttpError(WebResponse::STATUS_NOT_ACCEPTABLE, "Could not render the resource in an accepted format.", "Invalid accepted types: " . "[" . $formats->join(', ') . "] not supported by " . "[" . implode(', ', array_keys($this->renderers)) . "]");
     }
     $response = new WebResponse(call_user_func($this->renderers['']));
     if (!$formats->isEmpty()) {
         $response->getHeaders()->set(WebResponse::HEADER_CONTENT_TYPE, MimeTypes::getType($formats->first()));
     }
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * @param WebRequest $request
  * @throws \watoki\curir\error\HttpError
  * @return WebResponse
  */
 public function createResponse(WebRequest $request)
 {
     $formats = $request->getFormats();
     foreach ($formats as $format) {
         try {
             $response = new WebResponse($this->render($format));
             $response->getHeaders()->set(WebResponse::HEADER_CONTENT_TYPE, MimeTypes::getType($format));
             return $response;
         } catch (\ReflectionException $e) {
         }
     }
     throw new HttpError(WebResponse::STATUS_NOT_ACCEPTABLE, "Could not render the resource in an accepted format.", "Invalid accepted types: [" . $formats->join(', ') . "]");
 }
Ejemplo n.º 4
0
 /**
  * @return mixed
  */
 function respond()
 {
     $response = new WebResponse($this->content);
     if (strpos($this->key, '.') !== false) {
         $parts = explode('.', $this->key);
         $response->getHeaders()->set(WebResponse::HEADER_CONTENT_TYPE, MimeTypes::getType(end($parts)));
     } else {
         if (!$this->webRequest->getFormats()->isEmpty()) {
             $response->getHeaders()->set(WebResponse::HEADER_CONTENT_TYPE, MimeTypes::getType($this->webRequest->getFormats()->first()));
         }
     }
     return $response;
 }
Ejemplo n.º 5
0
 /**
  * @param WebResponse|mixed $response
  * @throws \Exception if $response is not a WebResponse
  * @return null
  */
 public function deliver($response)
 {
     if ($response instanceof WebResponse) {
         if ($response->getStatus()) {
             header('HTTP/1.1 ' . $response->getStatus());
         }
         foreach ($response->getHeaders() as $header => $value) {
             if (!is_null($value)) {
                 header($header . ': ' . $value);
             }
         }
     }
     $this->cookies->applyCookies('setcookie');
     echo $response;
 }
Ejemplo n.º 6
0
 function __construct(WebRequest $request, \Exception $exception)
 {
     parent::__construct('');
     $this->request = $request;
     $this->exception = $exception;
 }
Ejemplo n.º 7
0
Archivo: Box.php Proyecto: watoki/boxes
 public function getModel()
 {
     return $this->response->getBody();
 }
Ejemplo n.º 8
0
 public function thenTheResponseShouldBeARedirectionTo($url)
 {
     $this->spec->assertArrayHasKey(WebResponse::HEADER_LOCATION, $this->response->getHeaders()->toArray());
     $this->spec->assertEquals($url, $this->response->getHeaders()->get(WebResponse::HEADER_LOCATION));
 }
Ejemplo n.º 9
0
 private function thenTheContentTypeShouldBe($string)
 {
     $this->assertEquals($string, $this->response->getHeaders()->get(WebResponse::HEADER_CONTENT_TYPE));
 }