Пример #1
0
 /**
  * Write out as result set on the representation object that was determined - if no representation has been determined - defaults to text
  * @param ResultSet $resultSet
  */
 public function renderDeterminedRepresentation(ResultSet $resultSet)
 {
     $this->getResponse()->setBody($this->representation->output($resultSet));
     $this->getResponse()->setHttpHeader('Content-Type', $this->representation->getContentType());
 }
Пример #2
0
 /**
  * Determine the representation by inspecting the HTTP method
  * @param AbstractRepresentation $representation
  * @param array $detectContentOptions - Eg array(self::DETECT_CONTENT_HEADER => 'Accept')
  * @return AbstractRepresentation|null
  */
 protected function determineRepresentationByHttpMethod(AbstractRepresentation $representation, array $detectContentOptions = [])
 {
     switch ($this->request->getHttpMethod()) {
         // Match on content option
         case Request::METHOD_GET:
             // This representation matches the required media type requested by the client
             if ($representation->isExpectedContent($detectContentOptions, $this->request)) {
                 return $representation;
             }
             break;
             // Match on content-type
         // Match on content-type
         case Request::METHOD_POST:
         case Request::METHOD_PUT:
         case Request::METHOD_PATCH:
             if ($representation->getContentType() === $this->request->getHeaders('Content-Type')) {
                 return $representation;
             }
             break;
     }
     return null;
 }