Пример #1
0
 public function deserialize($data, $type, $format, DeserializationContext $context = null)
 {
     if (!$this->deserializationVisitors->containsKey($format)) {
         throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for deserialization.', $format));
     }
     if (null === $context) {
         $context = new DeserializationContext();
     }
     $context->initialize($format, $visitor = $this->deserializationVisitors->get($format)->get(), $this->navigator, $this->factory);
     $visitor->setNavigator($this->navigator);
     $navigatorResult = $this->navigator->accept($visitor->prepare($data), $this->typeParser->parse($type), $context);
     // This is a special case if the root is handled by a callback on the object iself.
     if (null === ($visitorResult = $visitor->getResult()) && null !== $navigatorResult) {
         return $navigatorResult;
     }
     return $visitorResult;
 }
Пример #2
0
 /**
  * Restores objects from an array structure.
  *
  * @param array $data
  * @param string $type
  *
  * @return mixed this returns whatever the passed type is, typically an object or an array of objects
  */
 public function fromArray(array $data, $type, DeserializationContext $context = null)
 {
     if (null === $context) {
         $context = new DeserializationContext();
     }
     return $this->deserializationVisitors->get('json')->map(function (JsonDeserializationVisitor $visitor) use($data, $type, $context) {
         $navigatorResult = $this->visit($visitor, $context, $data, 'json', $this->typeParser->parse($type));
         return $this->handleDeserializeResult($visitor->getResult(), $navigatorResult);
     })->get();
 }
Пример #3
0
 /**
  * @param       $path
  * @param       $format
  * @param array $options
  */
 public function dump($path, $format, array $options = array())
 {
     $metadata = $this->getDumpOrder($this->getAllMetadata());
     $generator = $this->generators->get($format)->get();
     $generator->setNavigator(new DefaultNavigator($this->handlerRegistry, $format));
     $generator->setManager($this->objectManager);
     $fixtures = array();
     foreach ($metadata as $data) {
         $fixture = $generator->generate($data, null, $options);
         if ($this->dumpMultipleFiles) {
             $fileName = $generator->createFileName($data, true);
             $this->writeFixture($generator, $fixture, $path, $fileName);
         } else {
             $fileName = $generator->createFileName($data, false);
         }
         $fixtures[] = $fixture;
     }
     if (!$this->dumpMultipleFiles && count($fixtures) != 0) {
         $fixture = implode("\n\n", $fixtures);
         $this->writeFixture($generator, $fixture, $path, $fileName);
     }
 }
Пример #4
0
 public function deserialize($data, $type, $format)
 {
     if (!$this->deserializationVisitors->containsKey($format)) {
         throw new UnsupportedFormatException(sprintf('The format "%s" is not supported for deserialization.', $format));
     }
     $visitor = $this->deserializationVisitors->get($format)->get();
     $visitor->setNavigator($navigator = new GraphNavigator(GraphNavigator::DIRECTION_DESERIALIZATION, $this->factory, $format, $this->handlerRegistry, $this->objectConstructor, $this->exclusionStrategy, $this->dispatcher));
     $navigatorResult = $navigator->accept($visitor->prepare($data), $this->typeParser->parse($type), $visitor);
     // This is a special case if the root is handled by a callback on the object iself.
     if (null === ($visitorResult = $visitor->getResult()) && null !== $navigatorResult) {
         return $navigatorResult;
     }
     return $visitorResult;
 }