Serialize a SerializableSerpPage object in the target format
@param  SerializableSerpPage $serializablePage
@param  string               $format
@return string
180829
public function serialize($serializablePage, $format)
    {
        // check if supported serialization format
        if (!SerpPageSerializerHelper::validFormat($format, self::$supportedFormatSerialization))
            throw new \Franzip\SerpPageSerializer\Exceptions\UnsupportedSerializationFormatException('Invalid SerpPageSerializer $format: supported serialization formats are JSON, XML and YAML.');
        // typecheck the object to serialize
        if (!SerpPageSerializerHelper::serializablePage($serializablePage))
            throw new \Franzip\SerpPageSerializer\Exceptions\NonSerializableObjectException('Invalid SerpPageSerializer $serializablePage: you must supply a SerializableSerpPage object to serialize.');

        $format           = strtolower($format);
        $entries          = $this->createEntries($serializablePage, $format);
        $serializablePage = $this->prepareForSerialization($serializablePage, $format, $entries);
        $serializedPage   = $this->getSerializer()->serialize($serializablePage, $format);
        // beautify output if JSON
        $content          = ($format == 'json') ? SerpPageSerializerHelper::prettyJSON($serializedPage) : $serializedPage;
        return new SerializedSerpPage($content);
    }
386981
public function serializeContent($content, $format = 'json')
    {
        try {
            return $this->getSerializer()->serialize(
                $content,
                $format
            );
        } catch (\Exception $e) {
            $msg = sprintf(
                'Cannot serialize content class: %s; with id: %s; Message: %s',
                get_class($content),
                method_exists($content, 'getId') ? $content->getId() : '-no id-',
                str_replace('MongoDBODMProxies\__CG__\GravitonDyn', '', $e->getMessage())
            );
            $this->logger->alert($msg);
            throw new \Exception($msg, $e->getCode());
        }
    }
62798
protected function serializePagination($pagination)
    {
        if ($this->serializedPagination !== null) {
            return $this->serializedPagination;
        }
        /** @var \yii\rest\Serializer $serializer */
        $serializer = $this->serializer;
        return $this->serializedPagination = [
            $serializer->linksEnvelope => \yii\web\Link::serialize($pagination->getLinks(true)),
            $serializer->metaEnvelope => [
                'totalCount' => $pagination->totalCount,
                'pageCount' => $pagination->getPageCount(),
                'currentPage' => $pagination->getPage() + 1,
                'perPage' => $pagination->getPageSize(),
            ],
        ];
    }
1270510
public function encode($data, $format, array $context = [])
    {
        $jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
        $encodedJson = json_encode($data, $jsonEncodeOptions);

        if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
            throw new NotEncodableValueException(json_last_error_msg());
        }

        return $encodedJson;
    }
975785
public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\SerializerInterface $serializer)
    {
        $pageSnapshot = $draftPage->getSnapshot();
        $contentRoute = $draftPage->getContentRoute();

        /** @var $publishedPage PageInterface */
        $publishedPage = $serializer->deserialize(
            $pageSnapshot->getVersionedData(),
            $this->getClassName(),
            'json'
        );

        // Save the layout blocks in a temp variable so that we can
        // assure the correct layout blocks will be saved and not
        // merged with the layout blocks from the draft page
        $tmpLayoutBlocks = $publishedPage->getLayoutBlock();

	    // tell the entity manager to handle our published page
	    // as if it came from the DB and not a serialized object
	    $publishedPage = $this->_em->merge($publishedPage);



        $contentRoute->setTemplate($pageSnapshot->getContentRoute()->getTemplate());
        $contentRoute->setTemplateName($pageSnapshot->getContentRoute()->getTemplateName());
        $contentRoute->setController($pageSnapshot->getContentRoute()->getController());
        $contentRoute->setPath($pageSnapshot->getContentRoute()->getPath());

        $this->_em->merge($contentRoute);

        $publishedPage->setContentRoute($contentRoute);

        // Set the layout blocks of the NOW managed entity to
        // exactly that of the published version
	    foreach ($tmpLayoutBlocks as $key => $layoutBlock){

		    try{
			    $layoutBlock = $this->_em->merge($layoutBlock);
		    }catch (EntityNotFoundException $e){
		    	$layoutBlock = clone $layoutBlock;
		    	$this->_em->persist($layoutBlock);
		    }

		    $this->resetContent($publishedPage, $layoutBlock, $serializer);

		    $tmpLayoutBlocks->set($key, $layoutBlock);
	    }

	    $publishedPage->resetLayoutBlock($tmpLayoutBlocks);
	    $this->_em->persist($publishedPage);
        $this->_em->flush();

        return $publishedPage;
    }
1261960
public function normalize($page, $format = null, array $context = [])
    {
        $data = parent::normalize($page, $format, $context);

        if ($this->contextHasGroup(['Default', 'Page'], $context)) {
            // Seo
            if (null !== $seo = $page->getSeo()) {
                $data['seo'] = $seo->getId();
            }
        } elseif ($this->contextHasGroup('Search', $context)) {
            // Seo
            if (null !== $seo = $page->getSeo()) {
                $data['seo'] = $this->normalizeObject($seo, $format, $context);
            }

            // TODO content.[locale]
        }

        return $data;
    }
906145
protected function createSitemapPage(Page $page, $multilingualEnabled)
    {
        $result = new SitemapPage($page, $this->getPageUrl($page));
        $lasMod = $page->getCollectionDateLastModified();
        if ($lasMod) {
            $result->setLastModifiedAt(new DateTime($lasMod));
        }
        $result
            ->setChangeFrequency($this->getPageChangeFrequency($page))
            ->setPriority($this->getPagePriority($page))
        ;

        if ($multilingualEnabled) {
            $this->populateLanguageAlternatives($result);
        }

        return $result;
    }
1374908
public function jsonSerialize($format = self::JSON_DEFAULT_FORMAT)
    {
        $data = [
            'uid'        => $this->_uid,
            'label'      => $this->_label,
            'type'       => $this->getContentType(),
            'state'      => $this->_state,
            'created'    => $this->_created->getTimestamp(),
            'modified'   => $this->_modified->getTimestamp(),
            'revision'   => $this->_revision,
            'parameters' => $this->getAllParams(),
            'accept'     => array_map(
                function ($classname) {
                    return str_replace(NAMESPACE_SEPARATOR, '/', $classname);
                },
                self::getShortClassname($this->getAccept())
            ),
            'minentry'   => $this->getMinEntry(),
            'maxentry'   => $this->getMaxEntry(),
            'elements'   => $this->computeElementsToJson($this->getData()),
            'has_elements' => count($this->getData()) === 0 ? false : true,
            'extra'      => [],
        ];

        if (0 === count($data['parameters'])) {
            $data['parameters'] = new \ArrayObject();
        }

        return $this->formatJsonData($data, $format);
    }
1021468
public function renderSerialized($var, $format)
    {
        if (is_string($var)) {
            $serialized = $var;
        } elseif (is_object($var)) {
            $toMethod = 'to' . ucFirst($format);
            
            if ($var instanceof \Rails\ActiveRecord\Relation) {
                $serialized = $var->records()->$toMethod();
            } else {
                if (is_callable([$var, $toMethod])) {
                    $serialized = $var->$toMethod();
                }
            }
        } elseif (is_array($var)) {
            if ($format == 'json') {
                $serialized = json_encode($var);
            } 
        }
        
        if (!isset($serialized)) {
            if (is_object($var)) {
                $message = sprintf(
                    "Can't serialize object of class %s to format %s",
                    get_class($var),
                    $format
                );
            } else {
                $message = sprintf(
                    "Can't serialize variable of type %s to format %s",
                    gettype($var),
                    $format
                );
            }
            throw new Exception\RuntimeException($message);
        }
        
        $this->controller->response()->setContentType(MimeTypes::getMimeType($format));
        return $serialized;
    }
917440
public function toString($format = Format::JSON, $options = [])
    {
        return StructureHelper::toString($this->data, $format, $options);
    }
1157185
private function createEntries($serializablePage, $format)
    {
        $result = array();
        $entries = $serializablePage->getEntries();
        for ($i = 0; $i < count($entries); $i++) {
            $args = array(($i + 1), $entries[$i]['url'], $entries[$i]['title'], $entries[$i]['snippet']);
            array_push($result, self::getFormatClassName($format, $args, true));
        }
        return $result;
    }
156868
protected function render_renderable(renderable $renderable) {
        $o = $this->render_table($renderable);
        $o .= $this->render_add_button($renderable->courseid);

        return $o;
    }
888000
protected function serializeArticle(ArticleInterface $object, $pageNumber)
    {
        return $this->get('jms_serializer')->serialize(
            $object,
            'array',
            SerializationContext::create()
                ->setSerializeNull(true)
                ->setGroups(['website', 'content'])
                ->setAttribute('website', true)
                ->setAttribute('pageNumber', $pageNumber)
        );
    }
897704
public function index(Page $page, MediaDataTable $mediaDataTable)
    {
        return $mediaDataTable->with([
            'resource' => $page,
            'tabs' => 'adminarea.pages.tabs',
            'id' => "adminarea-pages-{$page->getRouteKey()}-media-table",
            'url' => route('adminarea.pages.media.store', ['page' => $page]),
        ])->render('cortex/foundation::adminarea.pages.datatable-dropzone');
    }
372510
public function visitWritableBearer(WritableBearerInterface $writableBearer)
    {

        $template = 'writable-bearer/' . $writableBearer->getType() . '.twig';

        return $this
            ->loadTemplate($template)
            ->render(
                [
                    "id" => $writableBearer->getId(),
                    "classes" => $writableBearer->getClasses(),
                    "data" => $writableBearer->getData(),
                    "writables" => $writableBearer->getWritables(),
                ]
            );
    }
307810
public function serialize(Paper $paper, array $options = [])
    {
        $serialized = [
            'id' => $paper->getUuid(),
            'number' => $paper->getNumber(),
            'finished' => !$paper->isInterrupted(),
            'user' => $paper->getUser() && !$paper->isAnonymized() ? $this->userSerializer->serialize($paper->getUser(), $options) : null,
            'startDate' => $paper->getStart() ? DateNormalizer::normalize($paper->getStart()) : null,
            'endDate' => $paper->getEnd() ? DateNormalizer::normalize($paper->getEnd()) : null,
            'structure' => json_decode($paper->getStructure(), true),
        ];

        // Adds detail information
        if (!in_array(Transfer::MINIMAL, $options)) {
            $serialized['answers'] = $this->serializeAnswers($paper, $options);
        }

        // Adds user score
        if (!in_array(Transfer::INCLUDE_USER_SCORE, $options)) {
            $serialized['score'] = $paper->getScore();
        }

        return $serialized;
    }
454522
public function toString(string $format = self::FORMAT_XML, bool $gzip = false): string
    {
        switch ($format) {
            case self::FORMAT_XML:
                return $this->toXmlString($gzip);
            case self::FORMAT_TXT:
                return $this->toTxtString($gzip);
            default:
                throw new \InvalidArgumentException('Unknown format');

        }
    }