|
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 ObjectEmbed |
|
13
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object |
|
14
|
|
|
*/ |
|
15
|
|
|
final class ObjectEmbed 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('object', $attributes, $children); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function withAttribute(string $name, string $value = null): ObjectEmbed |
|
25
|
|
|
{ |
|
26
|
|
|
if ($value) { |
|
|
|
|
|
|
27
|
|
|
$attribute = new StandardAttribute($name, $value); |
|
28
|
|
|
} else { |
|
29
|
|
|
$attribute = new BooleanAttribute($name); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return new ObjectEmbed($this->attributes->add($attribute), $this->children); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function withChild(ElementInterface $element): ObjectEmbed |
|
36
|
|
|
{ |
|
37
|
|
|
return new ObjectEmbed($this->attributes, $this->children->add($element)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function withData(string $url): ObjectEmbed |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->withAttribute('data', $url); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function withForm(string $id): ObjectEmbed |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->withAttribute('form', $id); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function withHeight(int $pixels): ObjectEmbed |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->withAttribute('height', $pixels); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function withName(string $name): ObjectEmbed |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->withAttribute('name', $name); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $mime |
|
62
|
|
|
* @return ObjectEmbed |
|
63
|
|
|
* @see http://www.iana.org/assignments/media-types/media-types.xhtml |
|
64
|
|
|
*/ |
|
65
|
|
|
public function withType(string $mime): ObjectEmbed |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->withAttribute('type', $mime); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function withTypeMustMatch(): ObjectEmbed |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->withAttribute('typemustmatch'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function withUseMap(string $name): ObjectEmbed |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->withAttribute('usemap', $name); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function withWidth(int $pixels): ObjectEmbed |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->withAttribute('width', $pixels); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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: