Zend\Mvc\Controller\AbstractRestfulController::requestHasContentType PHP Method

requestHasContentType() public method

Check if request has certain content type
public requestHasContentType ( Zend\Stdlib\RequestInterface $request, string | null $contentType = '' ) : boolean
$request Zend\Stdlib\RequestInterface
$contentType string | null
return boolean
    public function requestHasContentType(Request $request, $contentType = '')
    {
        /** @var $headerContentType \Zend\Http\Header\ContentType */
        $headerContentType = $request->getHeaders()->get('content-type');
        if (!$headerContentType) {
            return false;
        }
        $requestedContentType = $headerContentType->getFieldValue();
        if (strstr($requestedContentType, ';')) {
            $headerData = explode(';', $requestedContentType);
            $requestedContentType = array_shift($headerData);
        }
        $requestedContentType = trim($requestedContentType);
        if (array_key_exists($contentType, $this->contentTypes)) {
            foreach ($this->contentTypes[$contentType] as $contentTypeValue) {
                if (stripos($contentTypeValue, $requestedContentType) === 0) {
                    return true;
                }
            }
        }
        return false;
    }