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\Tag\EmptyTag; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Area |
12
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area |
13
|
|
|
*/ |
14
|
|
|
final class Area extends AbstractElement |
15
|
|
|
{ |
16
|
|
|
public function __construct(AttributeSet $attributes = null) |
17
|
|
|
{ |
18
|
|
|
$this->attributes = $attributes ?? new AttributeSet(); |
19
|
|
|
$this->tag = new EmptyTag('area', $attributes); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function withAttribute(string $name, string $value = null): Area |
23
|
|
|
{ |
24
|
|
|
if ($value) { |
|
|
|
|
25
|
|
|
$attribute = new StandardAttribute($name, $value); |
26
|
|
|
} else { |
27
|
|
|
$attribute = new BooleanAttribute($name); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return new Area($this->attributes->add($attribute)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function withAlt($text): Area |
34
|
|
|
{ |
35
|
|
|
return $this->withAttribute('alt', $text); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function withCoords($coords): Area |
39
|
|
|
{ |
40
|
|
|
return $this->withAttribute('coords', $coords); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function withDownload($filename = null): Area |
44
|
|
|
{ |
45
|
|
|
return $this->withAttribute('download', $filename); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function withHref($href): Area |
49
|
|
|
{ |
50
|
|
|
return $this->withAttribute('href', $href); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function withHrefLang($lang): Area |
54
|
|
|
{ |
55
|
|
|
return $this->withAttribute('hreflang', $lang); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function withMedia($media): Area |
59
|
|
|
{ |
60
|
|
|
return $this->withAttribute('media', $media); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function withRel($rel): Area |
64
|
|
|
{ |
65
|
|
|
return $this->withAttribute('rel', $rel); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function withShape($shape): Area |
69
|
|
|
{ |
70
|
|
|
return $this->withAttribute('shape', $shape); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function withTarget($target): Area |
74
|
|
|
{ |
75
|
|
|
return $this->withAttribute('target', $target); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function withType($type): Anchor |
79
|
|
|
{ |
80
|
|
|
return $this->withAttribute('type', $type); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: