Ejemplo n.º 1
0
 /**
  * @param ContainerInterface               $container
  * @param object|array|Iterator|null       $data
  * @param EncodingParametersInterface|null $parameters
  *
  * @return string
  */
 protected function encodeDataInternal(ContainerInterface $container, $data, EncodingParametersInterface $parameters = null)
 {
     $dataAnalyzer = $this->factory->createAnalyzer($container);
     $parameters = $this->getEncodingParameters($data, $dataAnalyzer, $parameters);
     $docWriter = $this->factory->createDocument();
     $parserManager = $this->factory->createManager($parameters);
     $interpreter = $this->factory->createReplyInterpreter($docWriter, $parameters);
     $parser = $this->factory->createParser($dataAnalyzer, $parserManager);
     $this->encoderOptions !== null && $this->encoderOptions->getUrlPrefix() !== null ? $docWriter->setUrlPrefix($this->encoderOptions->getUrlPrefix()) : null;
     foreach ($parser->parse($data) as $reply) {
         $interpreter->handle($reply);
     }
     if ($this->meta !== null) {
         $docWriter->setMetaToDocument($this->meta);
     }
     if (empty($this->links) === false) {
         $docWriter->setDocumentLinks($this->links);
     }
     if ($this->isAddJsonApiVersion === true) {
         $docWriter->addJsonApiVersion(self::JSON_API_VERSION, $this->jsonApiVersionMeta);
     } elseif ($this->encoderOptions !== null && $this->encoderOptions->isShowVersionInfo() === true) {
         $docWriter->addJsonApiVersion(self::JSON_API_VERSION, $this->encoderOptions->getVersionMeta());
     }
     $result = $this->encodeToJson($docWriter->getDocument());
     $this->resetEncodeParameters();
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function encode($data, $links = null, $meta = null, EncodingParametersInterface $parameters = null)
 {
     $docWriter = $this->documentFactory->createDocument();
     $parameters = $this->getEncodingParameters($data, $parameters);
     $parserManager = $this->parserFactory->createManager($parameters);
     $parser = $this->parserFactory->createParser($this->container, $parserManager);
     $interpreter = $this->handlerFactory->createReplyInterpreter($docWriter, $parameters);
     $this->encoderOptions !== null && $this->encoderOptions->getUrlPrefix() !== null ? $docWriter->setUrlPrefix($this->encoderOptions->getUrlPrefix()) : null;
     foreach ($parser->parse($data) as $reply) {
         $interpreter->handle($reply);
     }
     $meta === null ?: $docWriter->setMetaToDocument($meta);
     $links === null ?: $docWriter->setDocumentLinks($links);
     if ($this->encoderOptions !== null && $this->encoderOptions->isShowVersionInfo() === true) {
         $docWriter->addJsonApiVersion(self::JSON_API_VERSION, $this->encoderOptions->getVersionMeta());
     }
     return $this->encodeToJson($docWriter->getDocument());
 }