Пример #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());
 }
Пример #2
0
 /**
  * @return ParserReplyInterface
  */
 private function createReplyResourceCompleted()
 {
     return $this->parserFactory->createReply(ParserReplyInterface::REPLY_TYPE_RESOURCE_COMPLETED, $this->stack);
 }