ipl\BaseElement: implement generic void element...
...support fixes #999
This commit is contained in:
parent
15e87a15bb
commit
4ced1137cd
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,9 +22,4 @@ class Icon extends BaseElement
|
|||
{
|
||||
return new static($name, $attributes);
|
||||
}
|
||||
|
||||
public function forcesClosingTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue