1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Audio extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
protected $url; |
6
|
|
|
protected $caption; |
7
|
|
|
protected $accessibilityCaption; |
8
|
|
|
protected $expicitContent; |
9
|
|
|
protected $imageUrl; |
10
|
|
|
|
11
|
|
|
protected $roles = ['audio', 'music']; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param string $url |
15
|
|
|
* @param string $role |
16
|
|
|
* @param string $caption |
17
|
|
|
* @param string $accessibilityCaption |
18
|
|
|
* @param bool $explicitContent |
19
|
|
|
* @param string $imageUrl |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function __construct($url, $role, $caption, $accessibilityCaption = '', $explicitContent = false, $imageUrl = '') |
23
|
|
|
{ |
24
|
|
|
$this->setUrl($url); |
25
|
|
|
$this->setRole($role); |
26
|
|
|
$this->setCaption($caption); |
27
|
|
|
$this->setAccessibilityCaption($accessibilityCaption); |
28
|
|
|
$this->setExplicitContent($explicitContent); |
29
|
|
|
$this->setImageUrl($imageUrl); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private function setUrl($url) |
33
|
|
|
{ |
34
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL)) { |
35
|
|
|
throw new \ErrorException('Invalid url supplied.'); |
36
|
|
|
} |
37
|
|
|
$this->url = $url; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function getUrl() |
41
|
|
|
{ |
42
|
|
|
return $this->url; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function setCaption($caption) |
46
|
|
|
{ |
47
|
|
|
$this->caption = $caption; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function getCaption() |
51
|
|
|
{ |
52
|
|
|
return $this->caption; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function setAccessibilityCaption($accessibilityCaption) |
56
|
|
|
{ |
57
|
|
|
$this->accessibilityCaption = $accessibilityCaption; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function getAccessibilityCaption() |
61
|
|
|
{ |
62
|
|
|
return $this->accessibilityCaption; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function setExplicitContent($expicitContent) |
66
|
|
|
{ |
67
|
|
|
$this->expicitContent = $expicitContent; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function getExplicitContent() |
71
|
|
|
{ |
72
|
|
|
return $this->expicitContent; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function setImageUrl($imageUrl) |
76
|
|
|
{ |
77
|
|
|
if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) { |
78
|
|
|
throw new \ErrorException('Invalid url supplied.'); |
79
|
|
|
} |
80
|
|
|
$this->imageUrl = $imageUrl; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function getImageUrl() |
84
|
|
|
{ |
85
|
|
|
return $this->imageUrl; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getComponent() |
89
|
|
|
{ |
90
|
|
|
$component = new \stdClass(); |
91
|
|
|
$component->url = $this->getUrl(); |
92
|
|
|
$component->role = $this->getRole(); |
93
|
|
|
$component->caption = $this->getCaption(); |
94
|
|
|
$component->accessibilityCaption = $this->getAccessibilityCaption(); |
95
|
|
|
$component->expicitContent = $this->getExplicitContent(); |
96
|
|
|
$component->imageUrl = $this->getImageUrl(); |
97
|
|
|
return $component; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|