示例#1
0
 /**
  * Returns an accessor object with that you can easily access values from
  * the request body
  *
  * @param \PSX\Data\TransformerInterface $transformer
  * @param string $readerType
  * @return \PSX\Data\Accessor
  */
 protected function getAccessor(TransformerInterface $transformer = null, $readerType = null)
 {
     if ($this->_accessor === null) {
         $data = $this->extractor->extract($this->request, $transformer, $readerType);
         $accessor = new Accessor($this->validate, $data);
         $this->_accessor = $accessor;
     }
     return $this->_accessor;
 }
示例#2
0
文件: Importer.php 项目: seytar/psx
 /**
  * Imports data from an http message into an record. The reader which gets
  * used depends on the content type. If not other specified a transformer
  * for the content type gets loaded. If no transformer is available we
  * simply pass the data from the reader to the importer
  *
  * @param mixed $source
  * @param \PSX\Http\MessageInterface $message
  * @param \PSX\Data\TransformerInterface $transformer
  * @param string $readerType
  * @return \PSX\Data\RecordInterface
  */
 public function import($source, MessageInterface $message, TransformerInterface $transformer = null, $readerType = null)
 {
     $data = $this->extractor->extract($message, $transformer, $readerType);
     if (is_callable($source)) {
         $source = call_user_func_array($source, array($data));
     }
     $importer = $this->importerManager->getImporterBySource($source);
     if ($importer instanceof ImporterInterface) {
         if ($data === null) {
             throw new RuntimeException('No data available');
         }
         return $importer->import($source, $data);
     } else {
         throw new NotFoundException('Could not find fitting importer');
     }
 }
示例#3
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $response = $this->executeRequest($request, $configuration, $context);
     $data = $this->extractor->extract($response);
     return $this->response->build($response->getStatusCode(), [], $data);
 }
示例#4
0
    public function testExtractJsonExplicitReader()
    {
        $data = <<<TEXT
{"foo": "bar"}
TEXT;
        $message = new Message();
        $message->addHeader('Content-Type', 'text/plain');
        $message->setBody(new StringStream($data));
        $extractor = new Extractor(Environment::getService('reader_factory'), Environment::getService('transformer_manager'));
        $data = $extractor->extract($message, null, ReaderInterface::JSON);
        $expect = new \stdClass();
        $expect->foo = 'bar';
        $this->assertEquals($expect, $data);
    }