ipl\BaseElement: implement generic void element...

...support

fixes #999
This commit is contained in:
Thomas Gelf 2017-07-12 12:58:15 +02:00
parent 15e87a15bb
commit 4ced1137cd
2 changed files with 26 additions and 8 deletions

View File

@ -13,6 +13,23 @@ abstract class BaseElement extends Html
/** @var string */
protected $tag;
protected static $voidElements = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr'
];
/**
* @return Attributes
*/
@ -98,7 +115,7 @@ abstract class BaseElement extends Html
$tag = $this->getTag();
$this->assemble();
$content = $this->renderContent();
if (strlen($content) || $this->forcesClosingTag()) {
if (strlen($content) || $this->wantsClosingTag()) {
return sprintf(
'<%s%s>%s</%s>',
$tag,
@ -115,9 +132,15 @@ abstract class BaseElement extends Html
}
}
public function forcesClosingTag()
public function wantsClosingTag()
{
return false;
// TODO: There is more. SVG and MathML namespaces
return ! $this->isVoidElement();
}
public function isVoidElement()
{
return in_array($this->tag, self::$voidElements);
}
/**

View File

@ -22,9 +22,4 @@ class Icon extends BaseElement
{
return new static($name, $attributes);
}
public function forcesClosingTag()
{
return true;
}
}