/** * constructor of the controller * @param string $appName the name of the app * @param IRequest $request an instance of the request * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 */ public function __construct($appName, IRequest $request) { $this->appName = $appName; $this->request = $request; // default responders $this->responders = array('json' => function ($data) { if ($data instanceof DataResponse) { $response = new JSONResponse($data->getData(), $data->getStatus()); $response->setHeaders(array_merge($data->getHeaders(), $response->getHeaders())); return $response; } else { return new JSONResponse($data); } }); }
/** * constructor of the controller * @param string $appName the name of the app * @param IRequest $request an instance of the request * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 */ public function __construct($appName, IRequest $request) { $this->appName = $appName; $this->request = $request; // default responders $this->responders = array('json' => function ($data) { if ($data instanceof DataResponse) { $response = new JSONResponse($data->getData(), $data->getStatus()); $dataHeaders = $data->getHeaders(); $headers = $response->getHeaders(); // do not overwrite Content-Type if it already exists if (isset($dataHeaders['Content-Type'])) { unset($headers['Content-Type']); } $response->setHeaders(array_merge($dataHeaders, $headers)); return $response; } else { return new JSONResponse($data); } }); }
public function testHeader() { $headers = $this->json->getHeaders(); $this->assertEquals('application/json; charset=utf-8', $headers['Content-Type']); }