Exemplo n.º 1
0
 /**
  * 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');
     }
 }