template = $template; $this->compiler = $compiler; $this->component = $component; $this->structure = $structure; $this->logger = $logger; $this->jsonSerializer = $jsonSerializer ?? ObjectManager::getInstance()->get(JsonHexTag::class); } /** * Get result document root element \DOMElement * * @return \DOMElement */ public function getDocumentElement() { return $this->template->getDocumentElement(); } /** * Append layout configuration * * @return void */ public function appendLayoutConfiguration() { $layoutConfiguration = $this->wrapContent( $this->jsonSerializer->serialize($this->structure->generate($this->component)) ); $this->template->append($layoutConfiguration); } /** * Returns the string representation * * @return string */ public function __toString() { try { $templateRootElement = $this->getDocumentElement(); foreach ($templateRootElement->attributes as $name => $attribute) { if ('noNamespaceSchemaLocation' === $name) { $this->getDocumentElement()->removeAttributeNode($attribute); break; } } $templateRootElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); $this->compiler->compile($templateRootElement, $this->component, $this->component); $this->appendLayoutConfiguration(); $result = $this->compiler->postprocessing($this->template->__toString()); } catch (\Exception $e) { $this->logger->critical($e->getMessage()); $result = $e->getMessage(); } return $result; } /** * Wrap content * * @param string $content * @return string */ protected function wrapContent($content) { return ''; } }