コード例 #1
0
ファイル: Pipe.php プロジェクト: virusvn/fusio
 public function handle(Request $request, Parameters $configuration, Context $context)
 {
     $response = $this->processor->execute($configuration->get('source'), $request, $context);
     $visitor = new StdClassSerializeVisitor();
     $traverser = new GraphTraverser();
     $traverser->traverse($response->getBody(), $visitor);
     $importer = $this->importerManager->getImporterByInstance('PSX\\Data\\Record\\Importer\\Record');
     $body = $importer->import(new Record(), $visitor->getObject());
     return $this->processor->execute($configuration->get('destination'), $request->withBody($body), $context);
 }
コード例 #2
0
ファイル: ModelFactory.php プロジェクト: seytar/psx
 public function factory($data)
 {
     if (!$data instanceof \stdClass) {
         throw new RuntimeException('Models must be an object');
     }
     $importer = $this->importerManager->getImporterByInstance('PSX\\Data\\Record\\Importer\\Record');
     $models = new \stdClass();
     foreach ($data as $name => $value) {
         $model = new Model();
         $model = $importer->import($model, $value);
         $model->setId($name);
         $models->{$name} = $model;
     }
     return $models;
 }
コード例 #3
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');
     }
 }
コード例 #4
0
ファイル: ObjectFactory.php プロジェクト: seytar/psx
 public function factory($data)
 {
     if ($data instanceof \stdClass) {
         $class = null;
         if (isset($data->objectType) && !empty($data->objectType)) {
             $class = $this->resolveType($data->objectType);
         }
         if ($class !== null && class_exists($class)) {
             $object = new $class();
         } else {
             $object = new Object();
         }
         $importer = $this->importerManager->getImporterByInstance('PSX\\Data\\Record\\Importer\\Record');
         return $importer->import($object, $data);
     } elseif (is_array($data)) {
         $objects = array();
         foreach ($data as $row) {
             $objects[] = $this->factory($row);
         }
         return $objects;
     } else {
         return $data;
     }
 }
コード例 #5
0
ファイル: Data.php プロジェクト: seytar/psx
 /**
  * @return \PSX\Data\Record\ImporterManager
  */
 public function getImporterManager()
 {
     $manager = new ImporterManager();
     $manager->addImporter(new Importer\Record($this->get('record_factory_factory')), 16);
     $manager->addImporter(new Importer\Schema($this->get('schema_assimilator')), 8);
     $manager->addImporter(new Importer\Table(), 0);
     return $manager;
 }