/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/View/Helper/SecureHtmlRender/HtmlRenderer.php
97 строк
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2020 Adobe * All Rights Reserved. */ namespace Magento\Framework\View\Helper\SecureHtmlRender; use Magento\Framework\Escaper; /** * Renders HTML based on provided data. */ class HtmlRenderer { /** * List of void elements which require a self-closing tag and don't allow content * * @var array */ private const VOID_ELEMENTS_MAP = [ 'area' => true, 'base' => true, 'br' => true, 'col' => true, 'command' => true, 'embed' => true, 'hr' => true, 'img' => true, 'input' => true, 'keygen' => true, 'link' => true, 'meta' => true, 'param' => true, 'source' => true, 'track' => true, 'wbr' => true, ]; /** * @var Escaper */ private $escaper; /** * @param Escaper $escaper */ public function __construct(Escaper $escaper) { $this->escaper = $escaper; } /** * Render the tag. * * @param TagData $tagData * @return string */ public function renderTag(TagData $tagData): string { $attributesHtmls = []; foreach ($tagData->getAttributes() as $attribute => $value) { $attributesHtmls[] = $attribute . '="' .$this->escaper->escapeHtmlAttr($value) .'"'; } $content = null; if ($tagData->getContent() !== null) { $content = $tagData->isTextContent() ? $this->escaper->escapeHtml($tagData->getContent()) : $tagData->getContent(); } $attributesHtml = ''; if ($attributesHtmls) { $attributesHtml = ' ' .implode(' ', $attributesHtmls); } $html = '<' .$tagData->getTag() .$attributesHtml; if (isset(self::VOID_ELEMENTS_MAP[$tagData->getTag()])) { $html .= '/>'; } else { $html .= '>' .$content .'</' .$tagData->getTag() .'>'; } return $html; } /** * Render the handler as an HTML attribute. * * @param EventHandlerData $eventHandlerData * @return string */ public function renderEventHandler(EventHandlerData $eventHandlerData): string { return $eventHandlerData->getEvent() .'="' .$this->escaper->escapeHtmlAttr($eventHandlerData->getCode()) .'"'; } }