commit 9547029ddbc1d727463a85275d8e00f6a6bb9704
parent 2ae66d6ebb4547f40e8838cda494095b4d0715e7
Author: Jan Dankert <develop@jandankert.de>
Date: Thu, 22 Oct 2020 12:01:12 +0200
Externalize void elements into class constant.
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/modules/template_engine/element/HtmlElement.class.php b/modules/template_engine/element/HtmlElement.class.php
@@ -9,6 +9,13 @@ use template_engine\components\html\Component;
class HtmlElement extends Element
{
+ /**
+ * HTML "void elements", these are self-closable.
+ * see HTML5 spec https://html.spec.whatwg.org/multipage/syntax.html#void-elements
+ * @var string[]
+ */
+ private static $VOID_ELEMENTS = ['area','base','br','col','embed','hr','img','input','link','meta','param','source','track','wbr'];
+
private $styleClasses = [];
/**
@@ -54,9 +61,8 @@ class HtmlElement extends Element
{
parent::__construct( $name );
- // Only "void elements" are self-closable, see
- // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
- if ( in_array($name,['area','base','br','col','embed','hr','img','input','link','meta','param','source','track','wbr']))
+ // Only "void elements" are self-closable
+ if ( in_array($name,HtmlElement::$VOID_ELEMENTS))
$this->selfClosing = true;
}