Exemplo n.º 1
2
 private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
 {
     $isRoot = null === $visitor->getRoot();
     $form = new \ArrayObject();
     $errors = [];
     foreach ($data->getErrors() as $error) {
         $errors[] = $this->getErrorMessage($error);
     }
     if (!empty($errors)) {
         $form['errors'] = $errors;
     }
     $children = [];
     foreach ($data->all() as $child) {
         if ($child instanceof Form) {
             $children[$child->getName()] = $this->convertFormToArray($visitor, $child);
         }
     }
     if (!empty($children)) {
         $form['children'] = $children;
     }
     if ($isRoot) {
         $visitor->setRoot($form);
     }
     return $form;
 }
 public function serializeToArray(GenericSerializationVisitor $visitor, Pagerfanta $pager, array $type, Context $context)
 {
     $resultsType = array('name' => 'array');
     if (isset($type['params'])) {
         $resultsType['params'] = $type['params'];
     }
     $shouldSetRoot = null === $visitor->getRoot();
     $data = array('page' => $pager->getCurrentPage(), 'limit' => $pager->getMaxPerPage(), 'total' => $pager->getNbResults(), 'results' => $visitor->getNavigator()->accept($pager->getCurrentPageResults(), $resultsType, $context));
     if (null !== ($links = $this->linkEventSubscriber->getOnPostSerializeData(new ObjectEvent($context, $pager, $type)))) {
         $data[$this->linksJsonKey] = $links;
     }
     if (null !== ($relations = $this->embedderEventSubscriber->getOnPostSerializeData(new ObjectEvent($context, $pager, $type)))) {
         $data[$this->relationsJsonKey] = $relations;
     }
     if ($shouldSetRoot) {
         $visitor->setRoot($data);
     }
     return $data;
 }
 /**
  * Normalize event container to serialize with generic serialization
  * Event class name is added
  *
  * @param GenericSerializationVisitor $visitor
  * @param EventContainer              $container
  * @param Context                     $context
  *
  * @return array
  */
 protected function serializeContainer(GenericSerializationVisitor $visitor, EventContainer $container, Context $context)
 {
     $setRoot = $visitor->getRoot() === null;
     $data = array('type' => $this->namingStrategy->classToType(get_class($container->getEvent())), 'data' => $visitor->getNavigator()->accept($container->getEvent(), null, $context));
     if ($setRoot) {
         $visitor->setRoot($data);
     }
     return $data;
 }
Exemplo n.º 4
0
 private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
 {
     $isRoot = null === $visitor->getRoot();
     $form = $errors = array();
     foreach ($data->getErrors() as $error) {
         $errors[] = $this->getErrorMessage($error);
     }
     if ($errors) {
         $form['errors'] = $errors;
     }
     $children = array();
     foreach ($data->getChildren() as $child) {
         $children[$child->getName()] = $this->convertFormToArray($visitor, $child);
     }
     if ($children) {
         $form['children'] = $children;
     }
     if ($isRoot) {
         $visitor->setRoot($form);
     }
     return $form;
 }