1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Tokens\Attribute; |
6
|
|
|
use Groundskeeper\Tokens\Element; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\FlowContent; |
8
|
|
|
use Groundskeeper\Tokens\ElementTypes\InteractiveContent; |
9
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
10
|
|
|
use Groundskeeper\Tokens\ElementTypes\PhrasingContent; |
11
|
|
|
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting; |
12
|
|
|
use Groundskeeper\Tokens\NonParticipating; |
13
|
|
|
use Psr\Log\LoggerInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* "select" element |
17
|
|
|
* |
18
|
|
|
* https://html.spec.whatwg.org/multipage/forms.html#the-select-element |
19
|
|
|
*/ |
20
|
|
|
class Select extends OpenElement implements FlowContent, InteractiveContent, PhrasingContent |
21
|
|
|
{ |
22
|
1 |
|
protected function getAllowedAttributes() |
23
|
|
|
{ |
24
|
|
|
$selectAllowedAttributes = array( |
25
|
1 |
|
'/^autocomplete$/i' => Attribute::CS_STRING, |
26
|
1 |
|
'/^autofocus$/i' => Attribute::BOOL, |
27
|
1 |
|
'/^disabled$/i' => Attribute::BOOL, |
28
|
1 |
|
'/^form$/i' => Attribute::CS_STRING, |
29
|
1 |
|
'/^multiple$/i' => Attribute::BOOL, |
30
|
1 |
|
'/^name$/i' => Attribute::CS_STRING, |
31
|
1 |
|
'/^type$/i' => Attribute::CI_ENUM . '("submit","reset","button","menu"|"submit")', |
32
|
|
|
'/^value$/i' => Attribute::CS_STRING |
33
|
1 |
|
); |
34
|
|
|
|
35
|
1 |
|
return array_merge( |
36
|
1 |
|
$selectAllowedAttributes, |
37
|
1 |
|
parent::getAllowedAttributes() |
38
|
1 |
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
View Code Duplication |
protected function removeInvalidChildren(LoggerInterface $logger) |
|
|
|
|
42
|
|
|
{ |
43
|
3 |
|
foreach ($this->children as $child) { |
44
|
3 |
|
if ($child instanceof NonParticipating || |
45
|
3 |
|
$child instanceof Option || |
46
|
2 |
|
$child instanceof Optgroup || |
47
|
3 |
|
$child instanceof ScriptSupporting) { |
48
|
3 |
|
continue; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$logger->debug('Removing ' . $child . '. Only "option, "optgroup", and script supporting elements allowed as children of a "select" element.'); |
52
|
1 |
|
$this->removeChild($child); |
53
|
3 |
|
} |
54
|
3 |
|
} |
55
|
|
|
|
56
|
1 |
|
public function isInteractiveContent() |
57
|
|
|
{ |
58
|
1 |
|
return true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.