コード例 #1
0
 /**
  * @inheritDoc
  */
 public function load($entity, ContextInterface $context)
 {
     $em = $this->getEntityManagerOf($entity);
     $emIdentifier = spl_object_hash($em);
     $em->persist($entity);
     if (!isset($this->entities[$emIdentifier])) {
         $this->entities[$emIdentifier] = ['em' => $em];
     }
     $this->entities[$emIdentifier]['entities'][] = $entity;
     if ($context->shouldFlush()) {
         $this->flush($context);
     }
 }
コード例 #2
0
 /**
  * @param ContextInterface $context
  * @throws FileException
  */
 public function flush(ContextInterface $context)
 {
     if (!$this->data) {
         $context->getLogger()->notice("Nothing to write.");
     } else {
         $jsonOutput = json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
         if ($jsonOutput === false) {
             throw new \RuntimeException(json_last_error_msg());
         }
         $write = file_put_contents($this->filePath, $jsonOutput);
         if ($write === false) {
             throw new FileException(sprintf("Unable to write into %s", $this->filePath));
         }
     }
 }
コード例 #3
0
 /**
  * @param $data
  * @param ContextInterface $context
  * @return mixed
  */
 public function transform($data, ContextInterface $context)
 {
     $context->setTransformedData($data);
     return $data;
 }