Phprest\Service\Hateoas\Util::serialize PHP Method

serialize() protected method

protected serialize ( mixed $value, Request $request, Response $response ) : Response
$value mixed
$request Symfony\Component\HttpFoundation\Request
$response Symfony\Component\HttpFoundation\Response
return Symfony\Component\HttpFoundation\Response
    protected function serialize($value, Request $request, Response $response)
    {
        $mimeProcResult = $this->processMime((new FormatNegotiator())->getBest($request->headers->get('Accept', '*/*'))->getValue());
        if ($mimeProcResult->mime === '*/*') {
            $mimeProcResult->mime = 'application/vnd.' . $mimeProcResult->vendor . '+json; version=' . $mimeProcResult->apiVersion;
            $mimeProcResult->format = 'json';
        }
        if (in_array($mimeProcResult->format, ['json', 'xml'])) {
            $response->setContent($this->serviceHateoas()->serialize($value, $mimeProcResult->format, SerializationContext::create()->setVersion($mimeProcResult->apiVersion)));
            $response->headers->set('Content-Type', $mimeProcResult->mime);
            return $response;
        }
        throw new Exception\NotAcceptable(0, [$mimeProcResult->mime . ' is not supported']);
    }