|
1
|
|
|
<?php namespace FlatPlan\Components; |
|
2
|
|
|
|
|
3
|
|
|
class Text extends AbstractComponent { |
|
4
|
|
|
|
|
5
|
|
|
protected $text; |
|
6
|
|
|
protected $format; |
|
7
|
|
|
protected $textStyle; |
|
8
|
|
|
|
|
9
|
|
|
protected $formats = ['html', 'markdown', 'none']; |
|
10
|
|
|
protected $roles = ['body', 'title', 'heading', 'intro', 'caption', 'author', 'byline', 'illustrator', 'photographer', 'quote', 'pullquote']; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @param string $text |
|
14
|
|
|
* @param string $role |
|
15
|
|
|
* @param string $format |
|
16
|
|
|
* @param string $textStyle |
|
17
|
|
|
* @return void |
|
18
|
|
|
*/ |
|
19
|
|
|
public function __construct($text, $role, $format = 'none', $textStyle = null) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->setText($text); |
|
22
|
|
|
$this->setRole($role); |
|
23
|
|
|
$this->setFormat($format); |
|
24
|
|
|
$this->setTextStyle($textStyle); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
private function setText($text) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->text = $text; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private function getText() |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->text; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function setFormat($format = null) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!in_array($format, $this->formats)) { |
|
40
|
|
|
throw new \ErrorException('Invalid format supplied.'); |
|
41
|
|
|
} |
|
42
|
|
|
$this->format = $format; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private function getFormat() |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->format; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function setTextStyle($textStyle) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->textStyle = $textStyle; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function getTextStyle() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->textStyle; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function getComponent() |
|
61
|
|
|
{ |
|
62
|
|
|
$component = new \stdClass(); |
|
63
|
|
|
$component->text = $this->getText(); |
|
64
|
|
|
$component->role = $this->getRole(); |
|
65
|
|
|
$component->format = $this->getFormat(); |
|
66
|
|
|
$component->textStyle = $this->getTextStyle(); |
|
67
|
|
|
return $component; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|