Esempio n. 1
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());
 }