protected function getRequestReader($contentType, $readerType) { // find best reader type if ($readerType === null) { $reader = $this->readerFactory->getReaderByContentType($contentType); } else { $reader = $this->readerFactory->getReaderByInstance($readerType); } if ($reader === null) { $reader = $this->readerFactory->getDefaultReader(); // @TODO the correct response would be to throw an unsupported // content type exception since this would enforce clients to send // an correct content type //throw new UnsupportedMediaTypeException('Unsupported content type', 415); } return $reader; }
public function testGetReaderByContentTypeSupportedReader() { $supportedReader = array('PSX\\Data\\Reader\\Form', 'PSX\\Data\\Reader\\Xml'); $contentType = 'application/xml'; $this->assertInstanceOf('PSX\\Data\\Reader\\Xml', $this->readerFactory->getReaderByContentType($contentType, $supportedReader)); }
/** * Returns the reader depending on the content type * * @return \PSX\Data\ReaderInterface */ private function getPreferredReader() { return $this->readerFactory->getReaderByContentType($this->request->getHeader('Content-Type')); }