/**
  * Serialize data object to id.
  *
  * @param VisitorInterface $visitor
  * @param object           $data
  * @param array            $type
  * @param Context          $context
  *
  * @return int|null
  */
 public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     $className = $this->manager->getClass();
     if ($data instanceof $className) {
         $galleryHasMedias = $data->getGalleryHasMedias();
         /* d($galleryHasMedias); */
         $galData = [];
         foreach ($galleryHasMedias as $galMedia) {
             $data = $galMedia->getMedia();
             $provider = $this->getPool()->getProvider($data->getProviderName());
             $format = 'wide';
             $format = $provider->getFormatName($data, $format);
             $options = $provider->getHelperProperties($data, $format, []);
             /*
                            d($options);
             */
             $options['width'] = null;
             $options['height'] = null;
             $html = $this->render($provider->getTemplate('helper_view'), array('media' => $data, 'format' => $format, 'options' => $options));
             $galData[] = ['id' => $data->getId(), 'width' => $data->getBox()->getWidth(), 'height' => $data->getBox()->getHeight(), 'url' => $provider->generatePublicUrl($data, $format), 'html' => $html];
         }
         /* dd($galData); */
         return $visitor->visitArray($galData, $type, $context);
     }
     return;
 }
 public function deserializeCollection(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     // See above. Set parameter type to PropelCollection<T> or PropelCollection<K,V>
     $type['name'] = 'array';
     $collection = new PropelCollection();
     $collection->setData($visitor->visitArray($data, $type, $context));
     return $collection;
 }
Esempio n. 3
0
 public function deserializeCollection(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     // See above.
     $type['name'] = 'array';
     // When there is not root set for the visitor we need to handle the vector result setting
     // manually this is related to https://github.com/schmittjoh/serializer/issues/95
     $isRoot = null === $visitor->getResult();
     if ($isRoot && $visitor instanceof GenericDeserializationVisitor) {
         $metadata = new ClassMetadata(Vector::class);
         $vector = new Vector();
         $visitor->startVisitingObject($metadata, $vector, $type, $context);
         $array = $visitor->visitArray($data, $type, $context);
         $vector->setAll($array);
         $visitor->endVisitingObject($metadata, $vector, $type, $context);
         return $vector;
     }
     // No a root so just return the vector
     return new Vector($visitor->visitArray($data, $type, $context));
 }
Esempio n. 4
0
 /**
  * @param VisitorInterface $visitor
  * @param Task[] $tasks
  * @param array $type
  * @param Context $context
  * @return string
  * @throws ReferenceException
  */
 public function serialize(VisitorInterface $visitor, $tasks, array $type, Context $context)
 {
     $list = [];
     foreach ($tasks as $task) {
         if (!$task->getUuid()) {
             throw new ReferenceException("you can't save a task that has dependencies to tasks that have not been saved");
         }
         $list[] = $task->getUuid();
     }
     return $visitor->visitArray($list, $type, $context);
 }
 /**
  * Serialize data object to id.
  *
  * @param VisitorInterface $visitor
  * @param object           $data
  * @param array            $type
  * @param Context          $context
  *
  * @return int|null
  */
 public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     $className = $this->manager->getClass();
     if ($data instanceof $className) {
         $provider = $this->getPool()->getProvider($data->getProviderName());
         $format = 'archive';
         /*$format = 'wide';*/
         $format = $provider->getFormatName($data, $format);
         $data = ['id' => $data->getId(), 'width' => $data->getBox()->getWidth(), 'height' => $data->getBox()->getHeight(), 'url' => $provider->generatePublicUrl($data, $format)];
         return $visitor->visitArray($data, $type, $context);
     }
 }
 public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context)
 {
     // We change the base type, and pass through possible parameters.
     $type['name'] = 'array';
     //don't include items that will produce null elements
     $dataArray = [];
     foreach ($collection->toArray() as $element) {
         if (!$context->isVisiting($element)) {
             $dataArray[] = $element;
         }
     }
     return $visitor->visitArray($dataArray, $type, $context);
 }
 /**
  * Serialize identifier(s).
  *
  * Converts an object or collection of objects to an id or array of ids.
  *
  * @param VisitorInterface $visitor
  * @param mixed $data
  * @param array $type
  * @param Context $context
  * @return
  */
 public function serializeIdentifier(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     if (!is_object($data)) {
         return;
     }
     if ($this->isIterable($data)) {
         $identifiers = array();
         foreach ($data as $datum) {
             $identifiers[] = $this->getIdentifier($datum);
         }
         return $visitor->visitArray($identifiers, $type, $context);
     }
     return $visitor->visitInteger($this->getIdentifier($data), $type, $context);
 }
 public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context)
 {
     $viewModelClass = null;
     if ($this->viewModel !== null) {
         $viewModelClass = get_class($this->viewModel);
     }
     // Only serialize to HalCollection when:
     // 1. We're not rendering a view model (viewModel is NULL). So we are respecting the defined type.
     // 2. We're actually rendering to Hal.
     // Note that we're using the class name because other view models might inherit from HalJsonModel...
     if ($viewModelClass == 'ZF\\Hal\\View\\HalJsonModel') {
         return new HalCollection($collection->toArray());
     }
     // We change the base type, and pass through possible parameters.
     $type['name'] = 'array';
     return $visitor->visitArray($collection->toArray(), $type, $context);
 }
 /**
  * Serialize data object to id.
  *
  * @param VisitorInterface $visitor
  * @param object           $data
  * @param array            $type
  * @param Context          $context
  *
  * @return int|null
  */
 public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     //$data is a -> Media
     /* dd(func_get_args()); */
     $className = $this->manager->getClass();
     if ($data instanceof $className) {
         $provider = $this->getPool()->getProvider($data->getProviderName());
         $format_reference = $provider->getFormatName($data, 'reference');
         $format_preview = $provider->getFormatName($data, 'prev');
         $options = ['width' => null, 'height' => null];
         $options = $provider->getHelperProperties($data, $format_reference, $options);
         /* $html = $this->render($provider->getTemplate('helper_view'), array( */
         $html = $this->render('AppBundle:Provider:view_video_api.html.twig', array('media' => $data, 'format' => $format_reference, 'options' => $options));
         $data = ['id' => $data->getId(), 'preview' => $provider->generatePublicUrl($data, $format_preview), 'reference' => $provider->generatePublicUrl($data, $format_reference), 'html' => $html];
         return $visitor->visitArray($data, $type, $context);
     }
     return;
     return $this->render($provider->getTemplate('helper_view'), array('media' => $media, 'format' => $format, 'options' => $options));
 }
 public function deserializeCollection(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     // See above.
     $type['name'] = 'array';
     return new ArrayCollection($visitor->visitArray($data, $type, $context));
 }
Esempio n. 11
0
 /**
  * Called for each node of the graph that is being traversed.
  *
  * @param mixed $data the data depends on the direction, and type of visitor
  * @param null|array $type array has the format ["name" => string, "params" => array]
  * @param VisitorInterface $visitor
  *
  * @return mixed the return value depends on the direction, and type of visitor
  */
 public function accept($data, array $type = null, VisitorInterface $visitor)
 {
     // If the type was not given, we infer the most specific type from the
     // input data in serialization mode.
     if (null === $type) {
         if (!$this->context->isSerializing()) {
             $msg = 'The type must be given for all properties when deserializing.';
             if (null !== ($path = $this->context->getPath())) {
                 $msg .= ' Path: ' . $path;
             }
             throw new \RuntimeException($msg);
         }
         $typeName = gettype($data);
         if ('object' === $typeName) {
             $typeName = get_class($data);
         }
         $type = array('name' => $typeName, 'params' => array());
     } else {
         if ($this->context->isSerializing() && null === $data) {
             $type = array('name' => 'NULL', 'params' => array());
         }
     }
     switch ($type['name']) {
         case 'NULL':
             return $visitor->visitNull($data, $type);
         case 'string':
             return $visitor->visitString($data, $type);
         case 'integer':
             return $visitor->visitInteger($data, $type);
         case 'boolean':
             return $visitor->visitBoolean($data, $type);
         case 'double':
         case 'float':
             return $visitor->visitDouble($data, $type);
         case 'array':
             return $visitor->visitArray($data, $type);
         case 'resource':
             $msg = 'Resources are not supported in serialized data.';
             if (null !== ($path = $this->context->getPath())) {
                 $msg .= ' Path: ' . $path;
             }
             throw new \RuntimeException($msg);
         default:
             $isSerializing = $this->context->isSerializing();
             if ($isSerializing && null !== $data) {
                 if ($this->context->isVisiting($data)) {
                     return null;
                 }
                 $this->context->startVisiting($data);
             }
             // First, try whether a custom handler exists for the given type. This is done
             // before loading metadata because the type name might not be a class, but
             // could also simply be an artifical type.
             if (null !== ($handler = $this->handlerRegistry->getHandler($this->context->getDirection(), $type['name'], $this->context->getFormat()))) {
                 $rs = call_user_func($handler, $visitor, $data, $type);
                 $this->context->stopVisiting($data);
                 return $rs;
             }
             // Trigger pre-serialization callbacks, and listeners if they exist.
             if ($isSerializing) {
                 if (null !== $this->dispatcher && $this->dispatcher->hasListeners('serializer.pre_serialize', $type['name'], $this->context->getFormat())) {
                     $this->dispatcher->dispatch('serializer.pre_serialize', $type['name'], $this->context->getFormat(), $event = new PreSerializeEvent($visitor, $data, $type));
                     $type = $event->getType();
                 }
             }
             // Load metadata, and check whether this class should be excluded.
             $metadata = $this->metadataFactory->getMetadataForClass($type['name']);
             if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipClass($metadata, $this->context)) {
                 $this->context->stopVisiting($data);
                 return null;
             }
             if ($isSerializing) {
                 foreach ($metadata->preSerializeMethods as $method) {
                     $method->invoke($data);
                 }
             }
             $object = $data;
             if (!$isSerializing) {
                 $object = $this->objectConstructor->construct($visitor, $metadata, $data, $type);
             }
             if (isset($metadata->handlerCallbacks[$this->context->getDirection()][$this->context->getFormat()])) {
                 $rs = $object->{$metadata->handlerCallbacks[$this->context->getDirection()][$this->context->getFormat()]}($visitor, $isSerializing ? null : $data);
                 $this->afterVisitingObject($visitor, $metadata, $object, $type);
                 return $isSerializing ? $rs : $object;
             }
             $visitor->startVisitingObject($metadata, $object, $type);
             foreach ($metadata->propertyMetadata as $propertyMetadata) {
                 if (null !== $this->exclusionStrategy && $this->exclusionStrategy->shouldSkipProperty($propertyMetadata, $this->context)) {
                     continue;
                 }
                 if (!$isSerializing && $propertyMetadata->readOnly) {
                     continue;
                 }
                 $visitor->visitProperty($propertyMetadata, $data);
             }
             if ($isSerializing) {
                 $this->afterVisitingObject($visitor, $metadata, $data, $type);
                 return $visitor->endVisitingObject($metadata, $data, $type);
             }
             $rs = $visitor->endVisitingObject($metadata, $data, $type);
             $this->afterVisitingObject($visitor, $metadata, $rs, $type);
             return $rs;
     }
 }
 public function deserializeSequence(VisitorInterface $visitor, $data, array $type)
 {
     // See above.
     $type['name'] = 'array';
     return new Sequence($visitor->visitArray($data, $type));
 }
Esempio n. 13
0
 public function serializeMetadata(VisitorInterface $visitor, Metadata $metadata, array $type, Context $context)
 {
     return $visitor->visitArray($metadata->toArray(), $type, $context);
 }
 /**
  * @param VisitorInterface $visitor
  * @param array            $data
  * @param array            $type
  * @param Context          $context
  * @return mixed
  */
 public function serializeJobParameterArray(VisitorInterface $visitor, array $data, array $type, Context $context)
 {
     return $visitor->visitArray($data, $type, $context);
 }
Esempio n. 15
0
 public function deserializeStdClass(VisitorInterface $visitor, $data, array $type, Context $context)
 {
     // See above.
     $type['name'] = 'array';
     return (object) $visitor->visitArray($data, $type, $context);
 }
Esempio n. 16
0
 public function serializeCollection(VisitorInterface $visitor, MapInterface $collection, array $type, Context $context)
 {
     // We change the base type, and pass through possible parameters.
     $type['name'] = 'array';
     return $visitor->visitArray($collection->toArray(), $type, $context);
 }