/** * Constructor. * * @param array $data Array to be serialized * @param string $format serialization format, text, xml or json available * @param integer $status The response status code * @param array $headers An array of response headers * * @throws \InvalidArgumentException When the HTTP status code is not valid * * @api */ public function __construct($data = null, $format = 'json', $status = 200, $headers = array()) { parent::__construct('', $status, $headers); if ($format == 'text') { if (isset($data)) { $this->setContent($data); } $this->headers->set('Content-Type', 'text/plain'); } else { $this->format = $format; $serializer = $this->getSerializer(); if (isset($data)) { $this->setContent($serializer->serialize($data, $this->format)); } $this->headers->set('Content-Type', 'application/' . $this->format); } }