1
|
|
|
<?php namespace FlatPlan\Components; |
2
|
|
|
|
3
|
|
|
class Image extends AbstractComponent { |
4
|
|
|
|
5
|
|
|
protected $url; |
6
|
|
|
protected $caption; |
7
|
|
|
protected $accessibilityCaption; |
8
|
|
|
protected $explicitContent; |
9
|
|
|
|
10
|
|
|
protected $roles = ['figure', 'image', 'logo', 'photo', 'portrait', 'galleryitem']; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param string $role |
14
|
|
|
* @param string $url |
15
|
|
|
* @param string $caption |
16
|
|
|
* @param string $accessibilityCaption |
17
|
|
|
* @param bool $explicitContent |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
|
|
public function __construct($role, $url, $caption = '', $accessibilityCaption = '', $explicitContent = false) |
21
|
|
|
{ |
22
|
|
|
$this->setUrl($url); |
23
|
|
|
$this->setRole($role); |
24
|
|
|
$this->setCaption($caption); |
25
|
|
|
$this->setAccessibilityCaption($accessibilityCaption); |
26
|
|
|
$this->setExplicitContent($explicitContent); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
private function setUrl($url) |
30
|
|
|
{ |
31
|
|
|
$parsedUrl = parse_url($url); |
32
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL, [ |
33
|
|
|
'flags' => FILTER_FLAG_PATH_REQUIRED |
34
|
|
|
]) || strlen($parsedUrl['path']) <= 1) { |
35
|
|
|
throw new \ErrorException('Invalid url supplied.'); |
36
|
|
|
} |
37
|
|
|
$this->url = $url; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private 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
|
|
|
public function getComponent() |
76
|
|
|
{ |
77
|
|
|
$component = new \stdClass(); |
78
|
|
|
// galleryitems do not have a role attribute. |
79
|
|
|
if ($this->getRole() !== 'galleryitem') { |
80
|
|
|
$component->role = $this->getRole(); |
81
|
|
|
} |
82
|
|
|
$component->URL = $this->getUrl(); |
83
|
|
|
$component->caption = $this->getCaption(); |
84
|
|
|
$component->accessibilityCaption = $this->getAccessibilityCaption(); |
85
|
|
|
$component->explicitContent = $this->getExplicitContent(); |
86
|
|
|
$component->layout = $this->getLayout(); |
87
|
|
|
$component->style = $this->getStyle(); |
88
|
|
|
if (!is_null($this->behaviour)) { |
89
|
|
|
$component->behaviour = $this->getBehaviour(); |
90
|
|
|
} |
91
|
|
|
return $component; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|