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 endVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context)
 {
     $rs = parent::endVisitingObject($metadata, $data, $type, $context);
     // Force JSON output to "{}" instead of "[]" if it contains either no properties or all properties are null.
     if (empty($rs)) {
         $rs = new \ArrayObject();
     }
     return $rs;
 }
 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;
 }
 public function endVisitingObject(ClassMetadata $metadata, $data, array $type, Context $context)
 {
     $rs = parent::endVisitingObject($metadata, $data, $type, $context);
     // Force JSON output to "{}" instead of "[]" if it contains either no properties or all properties are null.
     if (empty($rs)) {
         $rs = new \ArrayObject();
         if (array() === $this->getRoot() && 0 === $context->getDepth()) {
             $this->setRoot(clone $rs);
         }
     }
     return $rs;
 }
 public function testOnPostSerializeWithApiWrapper()
 {
     $apiWrapper = $this->prophesize(ApiWrapper::class);
     $entity = $this->prophesize(SecuredEntityInterface::class);
     $entity->getId()->willReturn(7);
     $entity->getSecurityContext()->willReturn('sulu.example');
     $apiWrapper->getEntity()->willReturn($entity);
     $this->objectEvent->getObject()->willReturn($apiWrapper);
     $securityCondition = new SecurityCondition('sulu.example', null, get_class($entity->reveal()), 7);
     $permission = ['_permissions' => ['permission' => 'value']];
     $this->accessControlManager->getUserPermissions($securityCondition, $this->user->reveal())->willReturn($permission);
     $this->visitor->addData('_permissions', $permission)->shouldBeCalled();
     $this->securedEntitySubscriber->onPostSerialize($this->objectEvent->reveal());
 }
 /**
  * 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;
 }
 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;
 }
 /**
  * @param GenericSerializationVisitor $visitor
  * @param string                      $contentAttributeValue
  * @param array                       $type
  * @param Context                     $context
  *
  * @return null|string
  */
 public function serializeFieldType(GenericSerializationVisitor $visitor, $contentAttributeValue, array $type, Context $context)
 {
     return $visitor->getNavigator()->accept($contentAttributeValue, null, $context);
 }