serializer = new Serializer([new ArrayDenormalizer()], [new XmlEncoder()]); } public function ok(array $data = []): ResponseInterface { return $this->xml($data, 200); } public function created(array $data = [], ?string $location = null): ResponseInterface { $res = $this->xml($data, 201); if ($location) { $res = $res->withHeader('Location', $location); } return $res; } public function noContent(): ResponseInterface { return $this->psr17->createResponse(204); } public function error(int $status, string $title, ?string $detail = null, array $extra = []): ResponseInterface { $payload = array_merge([ 'title' => $title, 'status' => $status, ], $detail !== null ? ['detail' => $detail] : [], $extra); return $this->xml(['error' => $payload], $status); } public function fromArray(array $payload, int $status = 200): ResponseInterface { return $this->xml($payload, $status); } private function xml(array $data, int $status): ResponseInterface { $xml = $this->serializer->serialize($data, 'xml'); $res = $this->psr17->createResponse($status) ->withHeader('Content-Type', 'application/xml'); $res->getBody()->write($xml); return $res; } }