|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RoyallTheFourth\HtmlDocument\Element; |
|
4
|
|
|
|
|
5
|
|
|
use RoyallTheFourth\HtmlDocument\Attribute\BooleanAttribute; |
|
6
|
|
|
use RoyallTheFourth\HtmlDocument\Attribute\StandardAttribute; |
|
7
|
|
|
use RoyallTheFourth\HtmlDocument\Set\AttributeSet; |
|
8
|
|
|
use RoyallTheFourth\HtmlDocument\Set\ElementSet; |
|
9
|
|
|
use RoyallTheFourth\HtmlDocument\Tag\Standard; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class TextArea |
|
13
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea |
|
14
|
|
|
*/ |
|
15
|
|
|
final class TextArea extends AbstractElement implements ParentElementInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->attributes = $attributes ?? new AttributeSet(); |
|
20
|
|
|
$this->children = $children ?? new ElementSet(); |
|
21
|
|
|
$this->tag = new Standard('textarea', $attributes, $children); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function withAttribute(string $name, string $value = null): TextArea |
|
25
|
|
|
{ |
|
26
|
|
|
if ($value) { |
|
|
|
|
|
|
27
|
|
|
$attribute = new StandardAttribute($name, $value); |
|
28
|
|
|
} else { |
|
29
|
|
|
$attribute = new BooleanAttribute($name); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return new TextArea($this->attributes->add($attribute), $this->children); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function withChild(ElementInterface $element): TextArea |
|
36
|
|
|
{ |
|
37
|
|
|
return new TextArea($this->attributes, $this->children->add($element)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function withAutoComplete(string $offOn): TextArea |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->withAttribute('autocomplete', $offOn); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function withAutoFocus(): TextArea |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->withAttribute('autofocus'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function withCols(int $charWidth = 20): TextArea |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->withAttribute('cols', $charWidth); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function withDisabled(): TextArea |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->withAttribute('disabled'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function withForm(string $id): TextArea |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->withAttribute('form', $id); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function withMaxLength(int $max): TextArea |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->withAttribute('maxlength', $max); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function withMinLength(int $min): TextArea |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->withAttribute('minlength', $min); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function withName(string $name): TextArea |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->withAttribute('name', $name); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function withPlaceholder(string $placeholder): TextArea |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->withAttribute('placeholder', $placeholder); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function withReadOnly(): TextArea |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->withAttribute('readonly'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function withRequired(): TextArea |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->withAttribute('required'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function withRows(int $rows): TextArea |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->withAttribute('rows', $rows); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function withSelectionDirection(string $direction): TextArea |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->withAttribute('selectionDirection', $direction); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function withSelectionEnd(int $index): TextArea |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->withAttribute('selectionEnd', $index); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function withSelectionStart(int $index): TextArea |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->withAttribute('selectionStart', $index); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function withSpellCheck(string $spellcheck): TextArea |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->withAttribute('spellcheck', $spellcheck); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function withWrap(string $wrap = 'soft'): TextArea |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->withAttribute('wrap', $wrap); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: