summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/html/src/HtmlElement.php
blob: 4f5d162887abad2a403800a40117f10f442a1665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace ipl\Html;

/**
 * The HtmlElement represents any HTML element
 *
 * A typical HTML element includes a tag, attributes and content.
 */
class HtmlElement extends BaseHtmlElement
{
    /**
     * Create a new HTML element from the given tag, attributes and content
     *
     * @param string     $tag        The tag for the element
     * @param Attributes $attributes The HTML attributes for the element
     * @param ValidHtml  ...$content The content of the element
     */
    public function __construct($tag, Attributes $attributes = null, ValidHtml ...$content)
    {
        $this->tag = $tag;

        if ($attributes !== null) {
            $this->getAttributes()->merge($attributes);
        }

        $this->setHtmlContent(...$content);
    }

    /**
     * Create a new HTML element from the given tag, attributes and content
     *
     * @param string $tag        The tag for the element
     * @param mixed  $attributes The HTML attributes for the element
     * @param mixed  $content    The content of the element
     *
     * @return static
     */
    public static function create($tag, $attributes = null, $content = null)
    {
        return new static($tag, Attributes::wantAttributes($attributes), ...Html::wantHtmlList($content));
    }
}