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
 /**
  * @return \PSX\Data\ReaderFactory
  */
 public function getReaderFactory()
 {
     $reader = new ReaderFactory();
     $reader->addReader(new Reader\Json(), 16);
     $reader->addReader(new Reader\Form(), 8);
     $reader->addReader(new Reader\Xml(), 0);
     return $reader;
 }
Exemple #3
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 #4
0
 /**
  * Returns the reader depending on the content type
  *
  * @return \PSX\Data\ReaderInterface
  */
 private function getPreferredReader()
 {
     return $this->readerFactory->getReaderByContentType($this->request->getHeader('Content-Type'));
 }