|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / dev2.destoffenstraat.com / vendor / magento / framework / View / TemplateEngine / Xhtml / |
Filename | /home/dev2.destoffenstraat.com/vendor/magento/framework/View/TemplateEngine/Xhtml/Compiler.php |
Size | 4.65 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 17-Aug-2025 10:26 |
Last modified | 07-Jan-2021 21:08 |
Last accessed | 22-Aug-2025 16:11 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\TemplateEngine\Xhtml;
use Magento\Framework\DataObject;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\AttributeInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\CdataInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\CommentInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\Element\ElementInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\TextInterface;
/**
* Class Compiler
*/
class Compiler implements CompilerInterface
{
/**
* @var TextInterface
*/
protected $compilerText;
/**
* @var AttributeInterface
*/
protected $compilerAttribute;
/**
* @var CdataInterface
*/
protected $compilerCdata;
/**
* @var CommentInterface
*/
protected $compilerComment;
/**
* @var ElementInterface[]
*/
protected $elementCompilers;
/**
* Postprocessing data
*
* @var array
*/
protected $data;
/**
* Constructor
*
* @param TextInterface $compilerText
* @param AttributeInterface $compilerAttribute
* @param AttributeInterface|CdataInterface $compilerCdata
* @param CommentInterface $compilerComment
* @param ElementInterface[] $elementCompilers
*/
public function __construct(
TextInterface $compilerText,
AttributeInterface $compilerAttribute,
CdataInterface $compilerCdata,
CommentInterface $compilerComment,
array $elementCompilers
) {
$this->compilerText = $compilerText;
$this->compilerAttribute = $compilerAttribute;
$this->compilerCdata = $compilerCdata;
$this->compilerComment = $compilerComment;
$this->elementCompilers = $elementCompilers;
}
/**
* The compilation of the template and filling in the data
*
* @param \DOMNode $node
* @param DataObject $processedObject
* @param DataObject $context
* @return void
*/
public function compile(\DOMNode $node, DataObject $processedObject, DataObject $context)
{
switch ($node->nodeType) {
case XML_TEXT_NODE:
$this->compilerText->compile($node, $processedObject);
break;
case XML_CDATA_SECTION_NODE:
$this->compilerCdata->compile($node, $processedObject);
break;
case XML_COMMENT_NODE:
$this->compilerComment->compile($node, $processedObject);
break;
default:
/** @var \DomElement $node */
if ($node->hasAttributes()) {
foreach ($node->attributes as $attribute) {
$this->compilerAttribute->compile($attribute, $processedObject);
}
}
$compiler = $this->getElementCompiler($node->nodeName);
if (null !== $compiler) {
$compiler->compile($this, $node, $processedObject, $context);
} elseif ($node->hasChildNodes()) {
foreach ($this->getChildNodes($node) as $child) {
$this->compile($child, $processedObject, $context);
}
}
}
}
/**
* Run postprocessing contents
*
* @param string $content
* @return string
*/
public function postprocessing($content)
{
$patternTag = preg_quote(CompilerInterface::PATTERN_TAG);
return preg_replace_callback(
'#' . $patternTag . '(.+?)' . $patternTag . '#',
function ($match) {
return $this->data[$match[1]] ?? '';
},
$content
);
}
/**
* Set postprocessing data
*
* @param string $key
* @param string $content
* @return void
*/
public function setPostprocessingData($key, $content)
{
$this->data[$key] = $content;
}
/**
* Get child nodes
*
* @param \DOMElement $node
* @return \DOMElement[]
*/
protected function getChildNodes(\DOMElement $node)
{
$childNodes = [];
foreach ($node->childNodes as $child) {
$childNodes[] = $child;
}
return $childNodes;
}
/**
* Get element compiler by name
*
* @param string $name
* @return ElementInterface
*/
protected function getElementCompiler($name)
{
if (isset($this->elementCompilers[$name])) {
return $this->elementCompilers[$name];
}
return null;
}
}
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\View\TemplateEngine\Xhtml;
use Magento\Framework\DataObject;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\AttributeInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\CdataInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\CommentInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\Element\ElementInterface;
use Magento\Framework\View\TemplateEngine\Xhtml\Compiler\TextInterface;
/**
* Class Compiler
*/
class Compiler implements CompilerInterface
{
/**
* @var TextInterface
*/
protected $compilerText;
/**
* @var AttributeInterface
*/
protected $compilerAttribute;
/**
* @var CdataInterface
*/
protected $compilerCdata;
/**
* @var CommentInterface
*/
protected $compilerComment;
/**
* @var ElementInterface[]
*/
protected $elementCompilers;
/**
* Postprocessing data
*
* @var array
*/
protected $data;
/**
* Constructor
*
* @param TextInterface $compilerText
* @param AttributeInterface $compilerAttribute
* @param AttributeInterface|CdataInterface $compilerCdata
* @param CommentInterface $compilerComment
* @param ElementInterface[] $elementCompilers
*/
public function __construct(
TextInterface $compilerText,
AttributeInterface $compilerAttribute,
CdataInterface $compilerCdata,
CommentInterface $compilerComment,
array $elementCompilers
) {
$this->compilerText = $compilerText;
$this->compilerAttribute = $compilerAttribute;
$this->compilerCdata = $compilerCdata;
$this->compilerComment = $compilerComment;
$this->elementCompilers = $elementCompilers;
}
/**
* The compilation of the template and filling in the data
*
* @param \DOMNode $node
* @param DataObject $processedObject
* @param DataObject $context
* @return void
*/
public function compile(\DOMNode $node, DataObject $processedObject, DataObject $context)
{
switch ($node->nodeType) {
case XML_TEXT_NODE:
$this->compilerText->compile($node, $processedObject);
break;
case XML_CDATA_SECTION_NODE:
$this->compilerCdata->compile($node, $processedObject);
break;
case XML_COMMENT_NODE:
$this->compilerComment->compile($node, $processedObject);
break;
default:
/** @var \DomElement $node */
if ($node->hasAttributes()) {
foreach ($node->attributes as $attribute) {
$this->compilerAttribute->compile($attribute, $processedObject);
}
}
$compiler = $this->getElementCompiler($node->nodeName);
if (null !== $compiler) {
$compiler->compile($this, $node, $processedObject, $context);
} elseif ($node->hasChildNodes()) {
foreach ($this->getChildNodes($node) as $child) {
$this->compile($child, $processedObject, $context);
}
}
}
}
/**
* Run postprocessing contents
*
* @param string $content
* @return string
*/
public function postprocessing($content)
{
$patternTag = preg_quote(CompilerInterface::PATTERN_TAG);
return preg_replace_callback(
'#' . $patternTag . '(.+?)' . $patternTag . '#',
function ($match) {
return $this->data[$match[1]] ?? '';
},
$content
);
}
/**
* Set postprocessing data
*
* @param string $key
* @param string $content
* @return void
*/
public function setPostprocessingData($key, $content)
{
$this->data[$key] = $content;
}
/**
* Get child nodes
*
* @param \DOMElement $node
* @return \DOMElement[]
*/
protected function getChildNodes(\DOMElement $node)
{
$childNodes = [];
foreach ($node->childNodes as $child) {
$childNodes[] = $child;
}
return $childNodes;
}
/**
* Get element compiler by name
*
* @param string $name
* @return ElementInterface
*/
protected function getElementCompiler($name)
{
if (isset($this->elementCompilers[$name])) {
return $this->elementCompilers[$name];
}
return null;
}
}