Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Compiler.php
Go to the documentation of this file.
1 <?php
7 
14 
18 class Compiler implements CompilerInterface
19 {
23  protected $compilerText;
24 
28  protected $compilerAttribute;
29 
33  protected $compilerCdata;
34 
38  protected $compilerComment;
39 
43  protected $elementCompilers;
44 
50  protected $data;
51 
61  public function __construct(
66  array $elementCompilers
67  ) {
68  $this->compilerText = $compilerText;
69  $this->compilerAttribute = $compilerAttribute;
70  $this->compilerCdata = $compilerCdata;
71  $this->compilerComment = $compilerComment;
72  $this->elementCompilers = $elementCompilers;
73  }
74 
83  public function compile(\DOMNode $node, DataObject $processedObject, DataObject $context)
84  {
85  switch ($node->nodeType) {
86  case XML_TEXT_NODE:
87  $this->compilerText->compile($node, $processedObject);
88  break;
89  case XML_CDATA_SECTION_NODE:
90  $this->compilerCdata->compile($node, $processedObject);
91  break;
92  case XML_COMMENT_NODE:
93  $this->compilerComment->compile($node, $processedObject);
94  break;
95  default:
97  if ($node->hasAttributes()) {
98  foreach ($node->attributes as $attribute) {
99  $this->compilerAttribute->compile($attribute, $processedObject);
100  }
101  }
102  $compiler = $this->getElementCompiler($node->nodeName);
103  if (null !== $compiler) {
104  $compiler->compile($this, $node, $processedObject, $context);
105  } elseif ($node->hasChildNodes()) {
106  foreach ($this->getChildNodes($node) as $child) {
107  $this->compile($child, $processedObject, $context);
108  }
109  }
110  }
111  }
112 
119  public function postprocessing($content)
120  {
121  $patternTag = preg_quote(CompilerInterface::PATTERN_TAG);
122  return preg_replace_callback(
123  '#' . $patternTag . '(.+?)' . $patternTag . '#',
124  function ($match) {
125  return $this->data[$match[1]] ?? '';
126  },
127  $content
128  );
129  }
130 
138  public function setPostprocessingData($key, $content)
139  {
140  $this->data[$key] = $content;
141  }
142 
149  protected function getChildNodes(\DOMElement $node)
150  {
151  $childNodes = [];
152  foreach ($node->childNodes as $child) {
153  $childNodes[] = $child;
154  }
155 
156  return $childNodes;
157  }
158 
165  protected function getElementCompiler($name)
166  {
167  if (isset($this->elementCompilers[$name])) {
168  return $this->elementCompilers[$name];
169  }
170 
171  return null;
172  }
173 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
compile(\DOMNode $node, DataObject $dataObject, DataObject $context)
__construct(TextInterface $compilerText, AttributeInterface $compilerAttribute, CdataInterface $compilerCdata, CommentInterface $compilerComment, array $elementCompilers)
Definition: Compiler.php:61
if(!isset($_GET['name'])) $name
Definition: log.php:14