Deserialize the given content throw an exception if something went wrong

@param string $content       Request content
@param string $documentClass Document class

@throws DeserializationException

@return object $record Document
346259
public function deserialize($content, $documentClass)
    {
        try {
            $record = $this->deserializeContent(
                $content,
                $documentClass
            );
        } catch (\Exception $e) {
            throw new DeserializationException("Deserialization failed", $e);
        }

        return $record;
    }
1154721
public function getForm($documentClass = null)
    {
        if (null === $documentClass) {
            $documentClass = $this->getDocumentClass();
        }

        $builder = new AnnotationBuilder();
        $form = $builder->createForm($documentClass);

        $hasDocument = false;
        foreach ($form->getElements() as $element) {
            if (method_exists($element, 'setObjectManager')) {
                $element->setObjectManager($this->getDocumentManager());
                $hasDocument = true;
            } elseif (method_exists($element, 'getProxy')) {
                $proxy = $element->getProxy();
                if (method_exists($proxy, 'setObjectManager')) {
                    $proxy->setObjectManager($this->getDocumentManager());
                    $hasDocument = true;
                }
            }
        }

        if ($hasDocument) {
            $hydrator = new DoctrineObjectHydrator($this->getDocumentManager(), $documentClass);
            $form->setHydrator($hydrator);
        } else {
            $form->setHydrator(new ClassMethods());
        }

        $form->add([
            'type' => 'Zend\Form\Element\Csrf',
            'name' => 'csrf',
            'attributes' => [
                'id' => 'csrf',
            ],
        ]);

        $submitElement = new \Zend\Form\Element\Button('submit');
        $submitElement->setAttributes([
            'type' => 'submit',
            'class' => 'btn btn-primary',
        ]);
        $submitElement->setLabel('Salvar');
        $form->add($submitElement, [
            'priority' => -100,
        ]);

        $cancelarElement = new \Zend\Form\Element\Button('cancelar');
        $cancelarElement->setAttributes([
            'type' => 'button',
            'class' => 'btn btn-default',
            'onclick' => 'top.location=\''.$this->url()
                ->fromRoute($this->getActionRoute('list')).'\'',
        ]);
        $cancelarElement->setLabel('Cancelar');
        $form->add($cancelarElement, [
            'priority' => -100,
        ]);

        return $form;
    }
1073646
protected function fill($document, \stdClass $object)
    {
        $metadata = $this->getMetadataFactory()->getMetadataFor(get_class($document));
        $propertyAnnotations = $this->getMetadataFactory()->getObjectPropertyAnnotations($document);

        foreach ($propertyAnnotations as $property => $annotation) {
            $documentProperty = $property;

            if ($annotation->name) {
                $property = $annotation->name;
            }

            if (property_exists($object, $property)) {
                $value = $this->hydrateValue($object->$property, $annotation);
                $metadata->setDocumentValue($document, $documentProperty, $value);
            }
        }

        if ($document instanceof Proxy) {
            $document->__setInitialized(true);
        }

        return $document;
    }
1201303
public static function parse($content, Document $document = null, &$offset = 0)
    {
        if (preg_match('/^\s*\[(?P<array>.*)/is', $content, $match)) {
            preg_match_all('/(.*?)(\[|\])/s', trim($content), $matches);

            $level = 0;
            $sub   = '';
            foreach ($matches[0] as $part) {
                $sub .= $part;
                $level += (strpos($part, '[') !== false ? 1 : -1);
                if ($level <= 0) {
                    break;
                }
            }

            // Removes 1 level [ and ].
            $sub        = substr(trim($sub), 1, -1);
            $sub_offset = 0;
            $values     = Element::parse($sub, $document, $sub_offset, true);

            $offset += strpos($content, '[') + 1;
            // Find next ']' position
            $offset += strlen($sub) + 1;

            return new self($values, $document);
        }

        return false;
    }
1250755
public static function parse($content, Document $document = null, &$offset = 0)
    {
        if (preg_match('/^\s*(?P<id>[0-9]+\s+[0-9]+\s+R)/s', $content, $match)) {
            $id = $match['id'];
            $offset += strpos($content, $id) + strlen($id);
            $id = str_replace(' ', '_', rtrim($id, ' R'));

            return new self($id, $document);
        }

        return false;
    }
337938
protected static function createDocumentWrapper($html, $contentType = null, $documentID = null) 
    {
        if (function_exists('domxml_open_mem')) {
            throw new Exception("Old PHP4 DOM XML extension detected. phpQuery won't work until this extension is enabled.");
        }
        //        $id = $documentID
        //            ? $documentID
        //            : md5(microtime());
        $document = null;
        if ($html instanceof DOMDOCUMENT) {
            if (self::getDocumentID($html)) {
                // document already exists in phpQuery::$documents, make a copy
                $document = clone $html;
            } else {
                // new document, add it to phpQuery::$documents
                $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
            }
        } else {
            $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
        }
        //        $wrapper->id = $id;
        // bind document
        phpQuery::$documents[$wrapper->id] = $wrapper;
        // remember last loaded document
        phpQuery::selectDocument($wrapper->id);
        return $wrapper->id;
    }
301879
public static function parse($content, Document $document, &$position = 0)
    {
        /** @var Header $header */
        if (substr(trim($content), 0, 2) == '<<') {
            $header = ElementStruct::parse($content, $document, $position);
        } else {
            $elements = ElementArray::parse($content, $document, $position);
            if ($elements) {
                $header = new self($elements->getRawContent(), null);//$document);
            } else {
                $header = new self(array(), $document);
            }
        }

        if ($header) {
            return $header;
        } else {
            // Build an empty header.
            return new self(array(), $document);
        }
    }
593253
function uploadTranslatable($document) {
		if (! isset ( $this->submission ) || ! isset ( $this->submission->ticket )) {
			throw new Exception ( "Submission not initialized." );
		}
		$this->_validateDocument ( $document );
		
		$documentInfo = $document->getDocumentInfo ( $this->submission );
		$resourceInfo = $document->getResourceInfo ();
		
		$submitDocumentWithBinaryResourceRequest = new submitDocumentWithBinaryResource ();
		
		$submitDocumentWithBinaryResourceRequest->documentInfo = $documentInfo;
		$submitDocumentWithBinaryResourceRequest->resourceInfo = $resourceInfo;
		$submitDocumentWithBinaryResourceRequest->data = $document->data;
		
		$documentTicket = $this->documentService->submitDocumentWithBinaryResource ( $submitDocumentWithBinaryResourceRequest )->return;
		if (isset ( $documentTicket )) {
			$this->submission->ticket = $documentTicket->submissionTicket;
		}
		
		return $documentTicket->ticketId;
	}
1243359
public function deserialize($class, $data)
    {
        $grade = $this->gradeRepo->findOneBy(['uuid' => $data['id']]);

        if (empty($grade)) {
            $grade = new Grade();
            $grade->setUuid($data['id']);
            $correction = $data['correction'] instanceof Correction ?
                $data['correction'] :
                $this->correctionRepo->findOneBy(['uuid' => $data['correction']]);
            $grade->setCorrection($correction);
            $criterion = $this->criterionRepo->findOneBy(['uuid' => $data['criterion']]);
            $grade->setCriterion($criterion);
        }
        if (isset($data['value'])) {
            $grade->setValue($data['value']);
        }

        return $grade;
    }
1161445
public static function parse($content, Document $document = null, &$offset = 0)
    {
        if (preg_match('/^\s*\<(?P<name>[A-F0-9]+)\>/is', $content, $match)) {
            $name    = $match['name'];
            $offset += strpos($content, '<' . $name) + strlen($name) + 2; // 1 for '>'
            // repackage string as standard
            $name    = '(' . self::decode($name, $document) . ')';
            $element = false;

            if (!($element = ElementDate::parse($name, $document))) {
                $element = ElementString::parse($name, $document);
            }

            return $element;
        }

        return false;
    }
1338014
public function deserialize($serializedObject, $objectClass)
    {
        return $this->serializer->deserialize(
            $serializedObject,
            $objectClass,
            'json',
            DeserializationContext::create()->setSerializeNull(true)->setGroups(['preview'])
        );
    }
1035502
public function getBulkWriteBuilder(string $documentClass): BulkWriteBuilder
    {
        $metadata = $this->metadataFactory->getClassMetadata($documentClass);

        return $this->bulkWriteBuilderFactory->getBulkWriteBuilder($this, $metadata->getCollectionName());
    }
46880
public function deserialize($class, $data)
    {
        $criterion = $this->criterionRepo->findOneBy(['uuid' => $data['id']]);

        if (empty($criterion)) {
            $criterion = new Criterion();
            $criterion->setUuid($data['id']);
        }

        if (isset($data['instruction'])) {
            $criterion->setInstruction($data['instruction']);
        }

        return $criterion;
    }
43024
public static function deserializeResource($entityClass, HalDocument $halDocument): HalResource
    {
        if (is_string($entityClass)) {
            /** @var Hydratable $entity */
            $entity = new $entityClass();
        } else {
            $entity = $entityClass($halDocument->getData());
        }

        $entity->hydrate($halDocument->getData(), $halDocument->getEmbeddedEntities());

        return new HalResource($entity, $halDocument->getLinks());
    }
1359691
public function decode($content)
    {
        $result       = null;
        $this->errors = new ErrorCollection();

        $documentAsArray = json_decode($content, true);
        if ($documentAsArray !== null) {
            $result = $this->parseDocument($documentAsArray);

            return $this->errors->count() <= 0 ? $result : null;
        } else {
            return null;
        }
    }
834543
public function unserialise($input, $class = null)
    {
        $reader = Reader::createFromString($input);

        $contents = $reader->fetchAll();

        // @deprecated for the moment
        // for ($i = 0; $i < count($contents); ++$i) {
        //     if ($i <= 0) {
        //         continue;
        //     }
        //
        //     $contents[$i] = array_combine($contents[0], $contents[$i]);
        // }

        if (!is_null($class)) {
            return (new Mapper())->map($contents, $class);
        }

        return $contents;
    }
373656
public function getCollectionByDocumentClass($documentClass): Collection
    {
        $metadata = $this->metadataFactory->getClassMetadata($documentClass);

        return $this->getCollection($metadata->getCollectionName(), $metadata->getCollectionOptions());
    }