| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html; |
| 4 |
|
| 5 |
/** |
| 6 |
* The HtmlElement represents any HTML element |
| 7 |
* |
| 8 |
* A typical HTML element includes a tag, attributes and content. |
| 9 |
*/ |
| 10 |
class HtmlElement extends BaseHtmlElement |
| 11 |
{ |
| 12 |
/** |
| 13 |
* Create a new HTML element from the given tag, attributes and content |
| 14 |
* |
| 15 |
* @param string $tag The tag for the element |
| 16 |
* @param ?Attributes $attributes The HTML attributes for the element |
| 17 |
* @param ValidHtml ...$content The content of the element |
| 18 |
*/ |
| 19 |
public function __construct($tag, ?Attributes $attributes = null, ValidHtml ...$content) |
| 20 |
{ |
| 21 |
$this->tag = $tag; |
| 22 |
|
| 23 |
if ($attributes !== null) { |
| 24 |
$this->getAttributes()->merge($attributes); |
| 25 |
} |
| 26 |
|
| 27 |
$this->setHtmlContent(...$content); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Create a new HTML element from the given tag, attributes and content |
| 32 |
* |
| 33 |
* @param string $tag The tag for the element |
| 34 |
* @param mixed $attributes The HTML attributes for the element |
| 35 |
* @param mixed $content The content of the element |
| 36 |
* |
| 37 |
* @return static |
| 38 |
*/ |
| 39 |
public static function create($tag, $attributes = null, $content = null) |
| 40 |
{ |
| 41 |
return new static($tag, Attributes::wantAttributes($attributes), ...Html::wantHtmlList($content)); |
| 42 |
} |
| 43 |
} |