Ejemplo n.º 1
0
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format(Response $response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $data = $response->data;
     if (isset($data['language'])) {
         $this->_feedWriter->setChannelElement('language', $data['language']);
     }
     if (!isset($data['pubDate'])) {
         $this->_feedWriter->setChannelElement('pubDate', date(DATE_RSS, time()));
     }
     if (isset($data['title'])) {
         $this->_feedWriter->setTitle($data['title']);
     }
     if (isset($data['link'])) {
         $this->_feedWriter->setLink($data['link']);
     }
     if (isset($data['description'])) {
         $this->_feedWriter->setDescription($data['description']);
     }
     if (isset($data['items']) && is_array($data['items'])) {
         if ($data['items']) {
             foreach ($data['items'] as $item) {
                 $newItem = $this->_feedWriter->createNewItem();
                 $newItem->addElementArray($item);
                 $this->_feedWriter->addItem($newItem);
             }
         }
     }
     $response->content = $this->_feedWriter->generateFeed();
 }
Ejemplo n.º 2
0
 /**
  * Adds the rate limit headers to the response
  * @param Response $response
  * @param integer $limit the maximum number of allowed requests during a period
  * @param integer $remaining the remaining number of allowed requests within the current period
  * @param integer $reset the number of seconds to wait before having maximum number of allowed requests again
  */
 public function addHeaders(Response $response, $limit, $remaining, $reset)
 {
     if ($this->sendHeaders) {
         $response->getHeaders()->set('X-Rate-Limit-Limit', $limit)->set('X-Rate-Limit-Remaining', $remaining)->set('X-Rate-Limit-Reset', $reset);
         $response->setStatusCode(429);
     }
 }
Ejemplo n.º 3
0
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $response->charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $response->content = $response->data;
 }
Ejemplo n.º 4
0
 /**
  * Formats response data in JSONP format.
  *
  * @param Response $response
  * @throws ResponseException
  */
 protected function formatJsonp($response)
 {
     $response->getHeaders()->set('Content-Type', 'application/javascript; charset=UTF-8');
     if (is_array($response->data) && isset($response->data['data'], $response->data['callback'])) {
         $response->content = sprintf('%s(%s);', $response->data['callback'], Json::encode($response->data['data']));
     } else {
         $response->content = '';
         throw new ResponseException("The 'jsonp' response requires that the data be an array consisting of both 'data' and 'callback' elements.");
     }
 }
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format(Response $response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     foreach ($response->data as $value) {
         $this->_sitemap->add($value['loc'], Helper::getValue($value['lastmod']), Helper::getValue($value['changefreq']), isset($value['priority']) ? $value['priority'] : null);
     }
     $response->content = $this->_sitemap->toString();
 }
Ejemplo n.º 6
0
 protected function convertResponse(ResponseInterface $psrResponse, Request $request)
 {
     $request->setContentType($psrResponse->getHeaderLine('Content-Type'));
     $this->response->request = $request;
     $this->response->version = $psrResponse->getProtocolVersion();
     $this->response->setStatusCode($psrResponse->getStatusCode(), $psrResponse->getReasonPhrase());
     foreach ($psrResponse->getHeaders() as $name => $value) {
         $this->response->getHeaders()->setDefault($name, $value);
     }
     $this->response->content = $psrResponse->getBody()->getContents();
     return $this->response;
 }
Ejemplo n.º 7
0
 /**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format($response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     $dom = new DOMDocument($this->version, $charset);
     $root = new DOMElement($this->rootTag);
     $dom->appendChild($root);
     $this->buildXml($root, $response->data);
     $response->content = trim($dom->saveXML());
 }
Ejemplo n.º 8
0
 /**
  * Returns image captcha.
  *
  * @param bool $session
  * @param Response $response
  * @return null
  */
 public function getImage($session = true, Response $response)
 {
     if (!($data = $this->generate($session))) {
         return null;
     }
     $response->getHeaders()->set('Pragma', 'public')->set('Expires', '0')->set('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')->set('Content-Transfer-Encoding', 'binary')->set('Content-type', $data['mimeType']);
     return $data['image'];
 }
Ejemplo n.º 9
0
Archivo: CORS.php Proyecto: romeoz/rock
 /**
  * Adds the CORS headers to the response
  * @param Response $response
  * @param array CORS headers which have been computed
  */
 public function addCorsHeaders($response, $headers)
 {
     if (!empty($headers)) {
         $responseHeaders = $response->getHeaders();
         foreach ($headers as $field => $value) {
             $responseHeaders->set($field, $value);
         }
     }
 }