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; }