|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mpyw\OpenGraph\Elements; |
|
4
|
|
|
|
|
5
|
|
|
use Mpyw\OpenGraph\Property; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* An OpenGraph video element. |
|
9
|
|
|
*/ |
|
10
|
|
|
class Video extends ElementBase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The URL of a video resource associated with the object. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
public $url; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* An alternate URL to use if a video resource requires HTTPS. |
|
21
|
|
|
* |
|
22
|
|
|
* @var null|string |
|
23
|
|
|
*/ |
|
24
|
|
|
public $secureUrl; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The MIME type of a video resource associated with the object. |
|
28
|
|
|
* |
|
29
|
|
|
* @var null|string |
|
30
|
|
|
*/ |
|
31
|
|
|
public $type; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The width of a video resource associated with the object in pixels. |
|
35
|
|
|
* |
|
36
|
|
|
* @var null|int |
|
37
|
|
|
*/ |
|
38
|
|
|
public $width; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The height of a video resource associated with the object in pixels. |
|
42
|
|
|
* |
|
43
|
|
|
* @var null|int |
|
44
|
|
|
*/ |
|
45
|
|
|
public $height; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param mixed $url URL to the video. |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function __construct($url) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->url = (string)$url; |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $name |
|
57
|
|
|
* @param mixed $value |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function setAttribute(string $name, $value): void |
|
60
|
|
|
{ |
|
61
|
|
|
switch ($name) { |
|
62
|
1 |
|
case Property::VIDEO_HEIGHT: |
|
63
|
1 |
|
$this->height = (int)$value; |
|
64
|
1 |
|
break; |
|
65
|
1 |
|
case Property::VIDEO_WIDTH: |
|
66
|
1 |
|
$this->width = (int)$value; |
|
67
|
1 |
|
break; |
|
68
|
1 |
|
case Property::VIDEO_TYPE: |
|
69
|
1 |
|
$this->type = (string)$value; |
|
70
|
1 |
|
break; |
|
71
|
1 |
|
case Property::VIDEO_SECURE_URL: |
|
72
|
1 |
|
$this->secureUrl = (string)$value; |
|
73
|
1 |
|
break; |
|
74
|
|
|
} |
|
75
|
1 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Gets all properties set on this element. |
|
79
|
|
|
* |
|
80
|
|
|
* @return Property[] |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getProperties(): array |
|
83
|
|
|
{ |
|
84
|
|
|
$properties = []; |
|
85
|
|
|
|
|
86
|
|
|
// URL must precede all other properties |
|
87
|
|
|
if ($this->url !== null) { |
|
88
|
|
|
$properties[] = new Property(Property::VIDEO_URL, $this->url); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if ($this->height !== null) { |
|
92
|
|
|
$properties[] = new Property(Property::VIDEO_HEIGHT, $this->height); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if ($this->secureUrl !== null) { |
|
96
|
|
|
$properties[] = new Property(Property::VIDEO_SECURE_URL, $this->secureUrl); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if ($this->type !== null) { |
|
100
|
|
|
$properties[] = new Property(Property::VIDEO_TYPE, $this->type); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if ($this->width !== null) { |
|
104
|
|
|
$properties[] = new Property(Property::VIDEO_WIDTH, $this->width); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $properties; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|