1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Video extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
protected $url; |
6
|
|
|
protected $aspectRatio; |
7
|
|
|
protected $caption; |
8
|
|
|
protected $accessibilityCaption; |
9
|
|
|
protected $explicitContent; |
10
|
|
|
protected $stillUrl; |
11
|
|
|
|
12
|
|
|
protected $roles = ['video', 'embedwebvideo', 'embedvideo']; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param string $role |
16
|
|
|
* @param string $url |
17
|
|
|
* @param float $aspectRatio |
18
|
|
|
* @param string $caption |
19
|
|
|
* @param string $accessibilityCaption |
20
|
|
|
* @param bool $explicitContent |
21
|
|
|
* @param string $stillUrl |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function __construct($role, $url, $aspectRatio = 1.777, $caption = '', $accessibilityCaption = '', $explicitContent = false, $stillUrl = null) |
25
|
|
|
{ |
26
|
|
|
$this->setRole($role); |
27
|
|
|
$this->setUrl($url); |
28
|
|
|
$this->setAspectRatio($aspectRatio); |
29
|
|
|
$this->setCaption($caption); |
30
|
|
|
$this->setAccessibilityCaption($accessibilityCaption); |
31
|
|
|
$this->setExplicitContent($explicitContent); |
32
|
|
|
if (!is_null($stillUrl)) { |
33
|
|
|
$this->setStillUrl($stillUrl); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function setUrl($url) |
38
|
|
|
{ |
39
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL)) { |
40
|
|
|
throw new \ErrorException('Invalid url supplied.'); |
41
|
|
|
} |
42
|
|
|
$this->url = $url; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function getUrl() |
46
|
|
|
{ |
47
|
|
|
return $this->url; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function setAspectRatio($aspectRatio) |
51
|
|
|
{ |
52
|
|
|
$this->aspectRatio = (float) $aspectRatio; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function getAspectRatio() |
56
|
|
|
{ |
57
|
|
|
return $this->aspectRatio; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function setCaption($caption) |
61
|
|
|
{ |
62
|
|
|
$this->caption = $caption; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function getCaption() |
66
|
|
|
{ |
67
|
|
|
return $this->caption; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function setAccessibilityCaption($accessibilityCaption) |
71
|
|
|
{ |
72
|
|
|
$this->accessibilityCaption = $accessibilityCaption; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function getAccessibilityCaption() |
76
|
|
|
{ |
77
|
|
|
return $this->accessibilityCaption; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function setExplicitContent($explicitContent) |
81
|
|
|
{ |
82
|
|
|
$this->explicitContent = $explicitContent; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function getExplicitContent() |
86
|
|
|
{ |
87
|
|
|
return $this->explicitContent; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
private function setStillUrl($url) |
91
|
|
|
{ |
92
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL)) { |
93
|
|
|
throw new \ErrorException('Invalid still url supplied.'); |
94
|
|
|
} |
95
|
|
|
$this->stillUrl = $url; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function getStillUrl() |
99
|
|
|
{ |
100
|
|
|
return $this->stillUrl; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getComponent() |
104
|
|
|
{ |
105
|
|
|
$component = new \stdClass(); |
106
|
|
|
$component->URL = $this->getUrl(); |
107
|
|
|
$component->role = $this->getRole(); |
108
|
|
|
$component->aspectRatio = $this->getAspectRatio(); |
109
|
|
|
$component->caption = $this->getCaption(); |
110
|
|
|
$component->accessibilityCaption = $this->getAccessibilityCaption(); |
111
|
|
|
$component->explicitContent = $this->getExplicitContent(); |
112
|
|
|
if ($component->role === 'video') { |
113
|
|
|
$component->stillURL = $this->getStillUrl(); |
114
|
|
|
} |
115
|
|
|
$component->layout = $this->getLayout(); |
116
|
|
|
$component->style = $this->getStyle(); |
117
|
|
|
if (!is_null($this->behaviour)) { |
118
|
|
|
$component->behaviour = $this->getBehaviour(); |
119
|
|
|
} |
120
|
|
|
return $component; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|