|
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\TagFactory; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class HtmlTag |
|
11
|
|
|
*/ |
|
12
|
|
|
class HtmlTag implements HtmlTagInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* The attribute factory classname. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $attribute_factory = AttributeFactory::class; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The attributes factory classname. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $attributes_factory = AttributesFactory::class; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The tag factory classname. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $tag_factory = TagFactory::class; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function tag( |
|
39
|
|
|
$name, |
|
40
|
|
|
array $attributes = [], |
|
41
|
|
|
$content = false, |
|
42
|
|
|
$attribute_factory = null, |
|
43
|
|
|
$attributes_factory = null, |
|
44
|
|
|
$tag_factory = null |
|
45
|
|
|
) { |
|
46
|
|
|
$static = new static(); |
|
47
|
|
|
|
|
48
|
|
|
$attributes_factory = null === $attributes_factory ? |
|
49
|
|
|
$static->attributes_factory : |
|
50
|
|
|
$attributes_factory; |
|
51
|
|
|
/** @var \drupol\htmltag\Attributes\AttributesFactoryInterface $attributes_factory */ |
|
52
|
|
|
$attributes_factory = (new \ReflectionClass($attributes_factory))->newInstance(); |
|
53
|
|
|
|
|
54
|
|
|
$attribute_factory = null === $attribute_factory ? |
|
55
|
|
|
$static->attribute_factory : |
|
56
|
|
|
$attribute_factory; |
|
57
|
|
|
/** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory */ |
|
58
|
|
|
$attribute_factory = (new \ReflectionClass($attribute_factory))->newInstance(); |
|
59
|
|
|
|
|
60
|
|
|
$tag_factory = null === $tag_factory ? |
|
61
|
|
|
$static->tag_factory : |
|
62
|
|
|
$tag_factory; |
|
63
|
|
|
/** @var \drupol\htmltag\Tag\TagFactoryInterface $tag_factory */ |
|
64
|
|
|
$tag_factory = (new \ReflectionClass($tag_factory))->newInstance(); |
|
65
|
|
|
|
|
66
|
|
|
return $tag_factory->getInstance( |
|
67
|
|
|
$name, |
|
68
|
|
|
$attributes, |
|
69
|
|
|
$content, |
|
70
|
|
|
$attributes_factory, |
|
71
|
|
|
$attribute_factory |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function attributes( |
|
79
|
|
|
array $attributes = [], |
|
80
|
|
|
$attribute_factory = null, |
|
81
|
|
|
$attributes_factory = null |
|
82
|
|
|
) { |
|
83
|
|
|
$static = new static(); |
|
84
|
|
|
|
|
85
|
|
|
$attributes_factory = null === $attributes_factory ? |
|
86
|
|
|
$static->attributes_factory : |
|
87
|
|
|
$attributes_factory; |
|
88
|
|
|
/** @var \drupol\htmltag\Attributes\AttributesFactoryInterface $attributes_factory */ |
|
89
|
|
|
$attributes_factory = (new \ReflectionClass($attributes_factory))->newInstance(); |
|
90
|
|
|
|
|
91
|
|
|
$attribute_factory = null === $attribute_factory ? |
|
92
|
|
|
$static->attribute_factory : |
|
93
|
|
|
$attribute_factory; |
|
94
|
|
|
/** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory */ |
|
95
|
|
|
$attribute_factory = (new \ReflectionClass($attribute_factory))->newInstance(); |
|
96
|
|
|
|
|
97
|
|
|
return $attributes_factory |
|
98
|
|
|
->getInstance( |
|
99
|
|
|
$attributes, |
|
100
|
|
|
$attribute_factory |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
public static function attribute( |
|
108
|
|
|
$name, |
|
109
|
|
|
$value, |
|
110
|
|
|
$attribute_factory = null |
|
111
|
|
|
) { |
|
112
|
|
|
$static = new static(); |
|
113
|
|
|
|
|
114
|
|
|
$attribute_factory = null === $attribute_factory ? |
|
115
|
|
|
$static->attribute_factory : |
|
116
|
|
|
$attribute_factory; |
|
117
|
|
|
/** @var \drupol\htmltag\Attribute\AttributeFactoryInterface $attribute_factory */ |
|
118
|
|
|
$attribute_factory = (new \ReflectionClass($attribute_factory))->newInstance(); |
|
119
|
|
|
|
|
120
|
|
|
return $attribute_factory |
|
121
|
|
|
->getInstance( |
|
122
|
|
|
$name, |
|
123
|
|
|
$value |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|