|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace drupol\htmltag; |
|
4
|
|
|
|
|
5
|
|
|
use drupol\htmltag\Attribute\AttributeFactory; |
|
6
|
|
|
use drupol\htmltag\Attributes\AttributesFactory; |
|
7
|
|
|
use drupol\htmltag\Tag\CommentFactory; |
|
8
|
|
|
use drupol\htmltag\Tag\TagFactory; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class HtmlTag |
|
12
|
|
|
*/ |
|
13
|
|
|
class HtmlTag implements HtmlTagInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The attribute factory classname. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $attribute_factory_classname = AttributeFactory::class; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The attributes factory classname. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $attributes_factory_classname = AttributesFactory::class; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The tag factory classname. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $tag_factory_classname = TagFactory::class; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The comment factory classname. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $comment_factory_classname = CommentFactory::class; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public static function tag( |
|
47
|
|
|
$name, |
|
48
|
|
|
array $attributes = [], |
|
49
|
|
|
$content = null, |
|
50
|
|
|
$attribute_factory_classname = null, |
|
51
|
|
|
$attributes_factory_classname = null, |
|
52
|
|
|
$tag_factory_classname = null |
|
53
|
|
|
) { |
|
54
|
1 |
|
$static = new static(); |
|
55
|
|
|
|
|
56
|
1 |
|
$attributes_factory_classname = null == $attributes_factory_classname ? |
|
|
|
|
|
|
57
|
1 |
|
$static->attributes_factory_classname : |
|
58
|
1 |
|
$attributes_factory_classname; |
|
59
|
|
|
|
|
60
|
1 |
|
$attribute_factory_classname = null == $attribute_factory_classname ? |
|
|
|
|
|
|
61
|
1 |
|
$static->attribute_factory_classname : |
|
62
|
1 |
|
$attribute_factory_classname; |
|
63
|
|
|
|
|
64
|
1 |
|
$tag_factory_classname = null == $tag_factory_classname ? |
|
|
|
|
|
|
65
|
1 |
|
$static->tag_factory_classname : |
|
66
|
1 |
|
$tag_factory_classname; |
|
67
|
|
|
/** @var \drupol\htmltag\Tag\TagFactoryInterface $tag_factory_classname */ |
|
68
|
1 |
|
$tag_factory_classname = (new \ReflectionClass($tag_factory_classname))->newInstance(); |
|
69
|
|
|
|
|
70
|
1 |
|
return $tag_factory_classname::build( |
|
71
|
1 |
|
$name, |
|
72
|
1 |
|
$attributes, |
|
73
|
1 |
|
$content, |
|
74
|
1 |
|
$attribute_factory_classname, |
|
75
|
1 |
|
$attributes_factory_classname |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
1 |
View Code Duplication |
public static function comment( |
|
|
|
|
|
|
83
|
|
|
$content = null, |
|
84
|
|
|
$comment_factory_classname = null |
|
85
|
|
|
) { |
|
86
|
1 |
|
$static = new static(); |
|
87
|
|
|
|
|
88
|
1 |
|
$comment_factory_classname = null == $comment_factory_classname ? |
|
89
|
1 |
|
$static->comment_factory_classname : |
|
90
|
1 |
|
$comment_factory_classname; |
|
91
|
|
|
|
|
92
|
|
|
/** @var \drupol\htmltag\Tag\CommentFactory $comment_factory_classname */ |
|
93
|
1 |
|
$comment_factory_classname = (new \ReflectionClass($comment_factory_classname))->newInstance(); |
|
94
|
|
|
|
|
95
|
1 |
|
return $comment_factory_classname::build( |
|
96
|
1 |
|
$content |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritdoc} |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public static function attributes( |
|
104
|
|
|
array $attributes = [], |
|
105
|
|
|
$attribute_factory_classname = null, |
|
106
|
|
|
$attributes_factory_classname = null |
|
107
|
|
|
) { |
|
108
|
1 |
|
$static = new static(); |
|
109
|
|
|
|
|
110
|
1 |
|
$attribute_factory_classname = null == $attribute_factory_classname ? |
|
|
|
|
|
|
111
|
1 |
|
$static->attribute_factory_classname : |
|
112
|
1 |
|
$attribute_factory_classname; |
|
113
|
|
|
|
|
114
|
1 |
|
$attributes_factory_classname = null == $attributes_factory_classname ? |
|
|
|
|
|
|
115
|
1 |
|
$static->attributes_factory_classname : |
|
116
|
1 |
|
$attributes_factory_classname; |
|
117
|
|
|
|
|
118
|
|
|
/** @var \drupol\htmltag\Attributes\AttributesFactoryInterface $attributes_factory_classname */ |
|
119
|
1 |
|
$attributes_factory_classname = (new \ReflectionClass($attributes_factory_classname))->newInstance(); |
|
120
|
|
|
|
|
121
|
1 |
|
return $attributes_factory_classname::build( |
|
122
|
1 |
|
$attributes, |
|
123
|
1 |
|
$attribute_factory_classname |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
1 |
View Code Duplication |
public static function attribute( |
|
|
|
|
|
|
131
|
|
|
$name, |
|
132
|
|
|
$value, |
|
133
|
|
|
$attribute_factory_classname = null |
|
134
|
|
|
) { |
|
135
|
1 |
|
$static = new static(); |
|
136
|
|
|
|
|
137
|
1 |
|
$attribute_factory_classname = null == $attribute_factory_classname ? |
|
|
|
|
|
|
138
|
1 |
|
$static->attribute_factory_classname : |
|
139
|
1 |
|
$attribute_factory_classname; |
|
140
|
|
|
|
|
141
|
|
|
/** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory_classname */ |
|
142
|
1 |
|
$attribute_factory_classname = (new \ReflectionClass($attribute_factory_classname))->newInstance(); |
|
143
|
|
|
|
|
144
|
1 |
|
return $attribute_factory_classname::build($name, $value); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|