1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Tokens\Element; |
6
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\InteractiveContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\ClosedElement; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\PhrasingContent; |
10
|
|
|
use Psr\Log\LoggerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* "input" element |
14
|
|
|
* |
15
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-input-element |
16
|
|
|
*/ |
17
|
|
|
class Input extends ClosedElement implements FlowContent, InteractiveContent, PhrasingContent |
18
|
|
|
{ |
19
|
|
|
protected function getAllowedAttributes() |
20
|
|
|
{ |
21
|
|
|
$inputAllowedAttributes = array( |
22
|
|
|
'/^accept$/i' => Element::ATTR_CI_STRING, |
23
|
|
|
'/^alt$/i' => Element::ATTR_CS_STRING, |
24
|
|
|
'/^autocomplete$/i' => Element::ATTR_CS_STRING, |
25
|
|
|
'/^autofocus$/i' => Element::ATTR_BOOL, |
26
|
|
|
'/^checked$/i' => Element::ATTR_BOOL, |
27
|
|
|
'/^dirname$/i' => Element::ATTR_CS_STRING, |
28
|
|
|
'/^disabled$/i' => Element::ATTR_CS_STRING, |
29
|
|
|
'/^form$/i' => Element::ATTR_CS_STRING, |
30
|
|
|
'/^formaction$/i' => Element::ATTR_URI, |
31
|
|
|
'/^formenctype$/i' => Element::ATTR_CS_STRING, |
32
|
|
|
'/^formmethod$/i' => Element::ATTR_CI_ENUM . '("","get","post","dialog"|"get")', |
33
|
|
|
'/^formnovalidate$/i' => Element::ATTR_BOOL, |
34
|
|
|
'/^formtarget$/i' => Element::ATTR_CS_STRING, |
35
|
|
|
'/^height$/i' => Element::ATTR_INT, |
36
|
|
|
'/^inputmode$/i' => Element::ATTR_CI_STRING, |
37
|
|
|
'/^list$/i' => Element::ATTR_CS_STRING, |
38
|
|
|
'/^max$/i' => Element::ATTR_CS_STRING, |
39
|
|
|
'/^maxlength$/i' => Element::ATTR_INT, |
40
|
|
|
'/^min$/i' => Element::ATTR_CS_STRING, |
41
|
|
|
'/^minlength$/i' => Element::ATTR_INT, |
42
|
|
|
'/^multiple$/i' => Element::ATTR_BOOL, |
43
|
|
|
'/^name$/i' => Element::ATTR_CS_STRING, |
44
|
|
|
'/^pattern$/i' => Element::ATTR_CS_STRING, |
45
|
|
|
'/^placeholder$/i' => Element::ATTR_CS_STRING, |
46
|
|
|
'/^readonly$/i' => Element::ATTR_BOOL, |
47
|
|
|
'/^required$/i' => Element::ATTR_BOOL, |
48
|
|
|
'/^size$/i' => Element::ATTR_INT, |
49
|
|
|
'/^src$/i' => Element::ATTR_URI, |
50
|
|
|
'/^step$/i' => Element::ATTR_CI_STRING, |
51
|
|
|
'/^type$/i' => Element::ATTR_CI_ENUM . '("hidden","text","search","tel","url","email","password","date","month","week","time","datetime-local","number","range","color","checkbox","radio","file","submit","image","reset","button"|"text")', |
52
|
|
|
'/^value$/i' => Element::ATTR_CS_STRING, |
53
|
|
|
'/^width$/i' => Element::ATTR_INT |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
return array_merge( |
57
|
|
|
$inputAllowedAttributes, |
58
|
|
|
parent::getAllowedAttributes() |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
protected function removeInvalidSelf(LoggerInterface $logger) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$input = new self($this->configuration, 'input'); |
65
|
|
|
if ($this->hasAncestor($input)) { |
66
|
|
|
$logger->debug('Removing ' . $this . '. Cannot be have "input" element ancestor.'); |
67
|
|
|
|
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function isInteractiveContent() |
75
|
|
|
{ |
76
|
|
|
if (!$this->hasAttribute('type')) { |
77
|
|
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->getAttribute('type') !== 'hidden'; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.