-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractBlockElement.php
More file actions
69 lines (59 loc) · 1.54 KB
/
AbstractBlockElement.php
File metadata and controls
69 lines (59 loc) · 1.54 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace PHPForge\Html\Base;
use PHPForge\Html\{
Attribute\Custom\HasAttributes,
Attribute\Custom\HasContent,
Attribute\HasClass,
Attribute\HasData,
Attribute\HasId,
Attribute\HasLang,
Attribute\HasStyle,
Attribute\HasTitle,
Attribute\Input\HasName,
HtmlBuilder
};
use PHPForge\Widget\Block;
/**
* Provides a foundation for creating HTML block elements with various attributes and content.
*/
abstract class AbstractBlockElement extends Block
{
use HasAttributes;
use HasClass;
use HasContent;
use HasData;
use HasId;
use HasLang;
use HasName;
use HasStyle;
use HasTitle;
protected array $attributes = [];
protected string $tagName = '';
/**
* Begin rendering the block element.
*
* @return string The opening tag of the block element.
*/
public function begin(): string
{
parent::begin();
$attributes = $this->attributes;
$attributes['id'] = $this->id;
return HtmlBuilder::begin($this->tagName, $attributes);
}
/**
* Generate the HTML representation of the element.
*
* @return string The HTML representation of the element.
*/
protected function run(): string
{
if ($this->isBeginExecuted() === false) {
$attributes = $this->attributes;
$attributes['id'] = $this->id;
return HtmlBuilder::create($this->tagName, $this->content, $attributes);
}
return HtmlBuilder::end($this->tagName);
}
}