getCharset() public method

Retrieves the response charset.
public getCharset ( ) : string
return string Character set
Exemplo n.º 1
0
 /**
  * @return string
  */
 protected function getCharset()
 {
     if ($this->response === null) {
         return null;
     }
     return $this->response->getCharset();
 }
 public function onEventResponse(Application $app, Response $response)
 {
     if (null === $response->getCharset()) {
         $response->setCharset($app->getParameter('charset'));
     }
     $response->prepare($app->getRequest());
 }
Exemplo n.º 3
0
 public function testGetCharset()
 {
     $response = new Response();
     $charsetOrigin = 'UTF-8';
     $response->setCharset($charsetOrigin);
     $charset = $response->getCharset();
     $this->assertEquals($charsetOrigin, $charset);
 }
Exemplo n.º 4
0
 public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
 {
     $listener = new ResponseListener('ISO-8859-15');
     $this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
     $response = new Response('foo');
     $request = Request::create('/');
     $request->setRequestFormat('application/json');
     $event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
     $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
     $this->assertEquals('ISO-8859-15', $response->getCharset());
 }
 protected function logResponse(Response $response, Request $request)
 {
     if ($response->getStatusCode() >= 500) {
         $color = LogLevel::ERROR;
     } elseif ($response->getStatusCode() >= 400) {
         $color = LogLevel::WARNING;
     } elseif ($response->getStatusCode() >= 300) {
         $color = LogLevel::NOTICE;
     } elseif ($response->getStatusCode() >= 200) {
         $color = LogLevel::INFO;
     } else {
         $color = LogLevel::INFO;
     }
     $msg = 'Response {response_status_code} for "{request_method} {request_uri}"';
     $context = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary());
     $this->logger->log($color, $msg, $context);
 }
Exemplo n.º 6
0
 /**
  * Filters the Response.
  *
  * @param EventInterface $event    An EventInterface instance
  * @param Response       $response A Response instance
  */
 public function filter(EventInterface $event, Response $response)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->get('request_type')) {
         return $response;
     }
     if (null === $response->getCharset()) {
         $response->setCharset($this->charset);
     }
     if ($response->headers->has('Content-Type')) {
         return $response;
     }
     $request = $event->get('request');
     $format = $request->getRequestFormat();
     if (null !== $format && ($mimeType = $request->getMimeType($format))) {
         $response->headers->set('Content-Type', $mimeType);
     }
     return $response;
 }
 /**
  * Get the response charset
  * @return string
  */
 public function getCharset()
 {
     return $this->response->getCharset();
 }
Exemplo n.º 8
0
 protected function evaluateResponseMethodNotAllowed(Response $response)
 {
     $this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
     $this->assertEquals(405, $response->getStatusCode(), 'Test status code 405 ' . $response->getContent());
 }
Exemplo n.º 9
0
 private function evaluateResponse200(Response $response)
 {
     $this->assertEquals(200, $response->getStatusCode(), 'Test status code ');
     $this->assertEquals('UTF-8', $response->getCharset(), 'Test charset response');
 }
 /**
  * Serialize the response object ready for caching
  *
  * @param  \Symfony\Component\HttpFoundation\Response   $response
  *
  * @return string
  */
 public function serializeResponse(Response $response)
 {
     return array('content' => $response->getContent(), 'headers' => $response->headers, 'version' => $response->getProtocolVersion(), 'statusCode' => $response->getStatusCode(), 'charset' => $response->getCharset());
 }
Exemplo n.º 11
0
 /**
  * @param Response $response
  * @param Request  $request
  *
  * @return array
  */
 protected function createContext(Response $response, Request $request)
 {
     $context = array('response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary(), 'request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'response_time' => $this->getTime($request), 'response_memory' => $this->getMemory());
     return $context;
 }