Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Result.php
Go to the documentation of this file.
1 <?php
7 
13 use Psr\Log\LoggerInterface;
14 
18 class Result implements ResultInterface
19 {
23  protected $template;
24 
28  protected $compiler;
29 
33  protected $component;
34 
38  protected $structure;
39 
43  protected $logger;
44 
52  public function __construct(
57  LoggerInterface $logger
58  ) {
59  $this->template = $template;
60  $this->compiler = $compiler;
61  $this->component = $component;
62  $this->structure = $structure;
63  $this->logger = $logger;
64  }
65 
71  public function getDocumentElement()
72  {
73  return $this->template->getDocumentElement();
74  }
75 
81  public function appendLayoutConfiguration()
82  {
83  $layoutConfiguration = $this->wrapContent(
84  json_encode($this->structure->generate($this->component), JSON_HEX_TAG)
85  );
86  $this->template->append($layoutConfiguration);
87  }
88 
94  public function __toString()
95  {
96  try {
97  $templateRootElement = $this->getDocumentElement();
98  foreach ($templateRootElement->attributes as $name => $attribute) {
99  if ('noNamespaceSchemaLocation' === $name) {
100  $this->getDocumentElement()->removeAttributeNode($attribute);
101  break;
102  }
103  }
104  $templateRootElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi');
105  $this->compiler->compile($templateRootElement, $this->component, $this->component);
106  $this->appendLayoutConfiguration();
107  $result = $this->compiler->postprocessing($this->template->__toString());
108  } catch (\Exception $e) {
109  $this->logger->critical($e->getMessage());
110  $result = $e->getMessage();
111  }
112  return $result;
113  }
114 
121  protected function wrapContent($content)
122  {
123  return '<script type="text/x-magento-init"><![CDATA['
124  . '{"*": {"Magento_Ui/js/core/app": ' . str_replace(['<![CDATA[', ']]>'], '', $content) . '}}'
125  . ']]></script>';
126  }
127 }
__construct(Template $template, CompilerInterface $compiler, UiComponentInterface $component, Structure $structure, LoggerInterface $logger)
Definition: Result.php:52
if(!isset($_GET['name'])) $name
Definition: log.php:14