1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Audio extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
protected $url; |
6
|
|
|
protected $caption; |
7
|
|
|
protected $accessibilityCaption; |
8
|
|
|
protected $explicitContent; |
9
|
|
|
protected $imageUrl; |
10
|
|
|
|
11
|
|
|
protected $roles = ['audio', 'music', 'podcast']; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param string $role |
15
|
|
|
* @param string $url |
16
|
|
|
* @param string $caption |
17
|
|
|
* @param string $accessibilityCaption |
18
|
|
|
* @param bool $explicitContent |
19
|
|
|
* @param string $imageUrl |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function __construct($role, $url, $caption = '', $accessibilityCaption = '', $explicitContent = false, $imageUrl = '') |
23
|
|
|
{ |
24
|
|
|
$this->setRole($role); |
25
|
|
|
$this->setUrl($url); |
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($explicitContent) |
66
|
|
|
{ |
67
|
|
|
$this->explicitContent = $explicitContent; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function getExplicitContent() |
71
|
|
|
{ |
72
|
|
|
return $this->explicitContent; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function setImageUrl($imageUrl) |
76
|
|
|
{ |
77
|
|
|
if (!empty($imageUrl) && !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
|
|
|
public function getComponent() |
89
|
|
|
{ |
90
|
|
|
$component = new \stdClass(); |
91
|
|
|
$component->URL = $this->getUrl(); |
92
|
|
|
$component->role = $this->getRole(); |
93
|
|
|
if ($this->getRole() !== 'podcast') { |
94
|
|
|
$component->caption = $this->getCaption(); |
95
|
|
|
$component->accessibilityCaption = $this->getAccessibilityCaption(); |
96
|
|
|
$component->explicitContent = $this->getExplicitContent(); |
97
|
|
|
$imageUrl = $this->getImageUrl(); |
98
|
|
|
if (!empty($imageUrl) && substr($imageUrl, 0, 4) === 'http') { |
99
|
|
|
// only add valid image urls |
100
|
|
|
$component->imageURL = $this->getImageUrl(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$component->layout = $this->getLayout(); |
105
|
|
|
$component->style = $this->getStyle(); |
106
|
|
|
if (!is_null($this->behaviour)) { |
107
|
|
|
$component->behaviour = $this->getBehaviour(); |
108
|
|
|
} |
109
|
|
|
return $component; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|