protected function negotiateContentType($request, $response)
    {
        if (!empty($this->formatParam) && ($format = $request->get($this->formatParam)) !== null) {
            if (is_array($format)) {
                throw new BadRequestHttpException("Invalid data received for GET parameter '{$this->formatParam}'.");
            }

            if (in_array($format, $this->formats)) {
                $response->format = $format;
                $response->acceptMimeType = null;
                $response->acceptParams = [];
                return;
            }

            throw new NotAcceptableHttpException('The requested response format is not supported: ' . $format);
        }

        $types = $request->getAcceptableContentTypes();
        if (empty($types)) {
            $types['*/*'] = [];
        }

        foreach ($types as $type => $params) {
            if (isset($this->formats[$type])) {
                $response->format = $this->formats[$type];
                $response->acceptMimeType = $type;
                $response->acceptParams = $params;
                return;
            }
        }

        foreach ($this->formats as $type => $format) {
            $response->format = $format;
            $response->acceptMimeType = $type;
            $response->acceptParams = [];
            break;
        }

        if (isset($types['*/*'])) {
            return;
        }

        throw new NotAcceptableHttpException('None of your requested media types is supported.');
    }
protected function negotiateContentType($request, $response)
    {
        if (!empty($this->formatParam) && ($format = $request->get($this->formatParam)) !== null) {
            if (is_array($format)) {
                throw new BadRequestHttpException("Invalid data received for GET parameter '{$this->formatParam}'.");
            }

            if (in_array($format, $this->formats)) {
                $response->format = $format;
                $response->acceptMimeType = null;
                $response->acceptParams = [];
                return;
            }

            throw new NotAcceptableHttpException('The requested response format is not supported: ' . $format);
        }

        $types = $request->getAcceptableContentTypes();
        if (empty($types)) {
            $types['*/*'] = [];
        }

        foreach ($types as $type => $params) {
            if (isset($this->formats[$type])) {
                $response->format = $this->formats[$type];
                $response->acceptMimeType = $type;
                $response->acceptParams = $params;
                return;
            }
        }

        foreach ($this->formats as $type => $format) {
            $response->format = $format;
            $response->acceptMimeType = $type;
            $response->acceptParams = [];
            break;
        }

        if (isset($types['*/*'])) {
            return;
        }

        throw new NotAcceptableHttpException('None of your requested media types is supported.');
    }
protected function negotiateContentType ( $ request , $ response ) { if ( ! empty ( $ this -> formatParam ) && ( $ format = $ request -> get ( $ this -> formatParam ) ) !== null ) { if ( is_array ( $ format ) ) { throw new BadRequestHttpException ( "Invalid data received for GET parameter '{$this->formatParam}'." ) ; } if ( in_array ( $ format , $ this -> formats ) ) { $ response -> format = $ format ; $ response -> acceptMimeType = null ; $ response -> acceptParams = [ ] ; return ; } throw new NotAcceptableHttpException ( 'The requested response format is not supported: ' . $ format ) ; } $ types = $ request -> getAcceptableContentTypes ( ) ; if ( empty ( $ types ) ) { $ types [ '*/*' ] = [ ] ; } foreach ( $ types as $ type => $ params ) { if ( isset ( $ this -> formats [ $ type ] ) ) { $ response -> format = $ this -> formats [ $ type ] ; $ response -> acceptMimeType = $ type ; $ response -> acceptParams = $ params ; return ; } } foreach ( $ this -> formats as $ type => $ format ) { $ response -> format = $ format ; $ response -> acceptMimeType = $ type ; $ response -> acceptParams = [ ] ; break ; } if ( isset ( $ types [ '*/*' ] ) ) { return ; } throw new NotAcceptableHttpException ( 'None of your requested media types is supported.' ) ; }
Negotiates the response format.
@param Request $request
@param Response $response
@throws BadRequestHttpException if an array received for GET parameter [[formatParam]].
@throws NotAcceptableHttpException if none of the requested content types is accepted.
Negotiates the response format .