Exemple #1
0
 public function testGetReaderByInstance()
 {
     $this->assertInstanceOf('PSX\\Data\\Reader\\Json', $this->readerFactory->getReaderByInstance('PSX\\Data\\Reader\\Json'));
     $this->assertInstanceOf('PSX\\Data\\Reader\\Form', $this->readerFactory->getReaderByInstance('PSX\\Data\\Reader\\Form'));
     $this->assertInstanceOf('PSX\\Data\\Reader\\Xml', $this->readerFactory->getReaderByInstance('PSX\\Data\\Reader\\Xml'));
     $this->assertEquals(null, $this->readerFactory->getReaderByInstance('PSX\\Data\\Reader\\Foo'));
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 /**
  * Returns the best reader for the given content type or throws an
  * unsupported media exception
  *
  * @param string $readerType
  * @return \PSX\Data\ReaderInterface
  */
 private function getRequestReader($readerType = null)
 {
     if ($readerType === null) {
         $reader = $this->getPreferredReader();
     } else {
         $reader = $this->readerFactory->getReaderByInstance($readerType);
     }
     if (!$reader instanceof ReaderInterface) {
         throw new StatusCode\UnsupportedMediaTypeException('Could not find fitting data reader');
     }
     return $reader;
 }