|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHPPresentation - A pure PHP library for reading and writing |
|
4
|
|
|
* presentations documents. |
|
5
|
|
|
* |
|
6
|
|
|
* PHPPresentation is free software distributed under the terms of the GNU Lesser |
|
7
|
|
|
* General Public License version 3 as published by the Free Software Foundation. |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. For the full list of |
|
11
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/PHPOffice/PHPPresentation |
|
14
|
|
|
* @copyright 2009-2015 PHPPresentation contributors |
|
15
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace PhpOffice\PhpPresentation\Style; |
|
19
|
|
|
|
|
20
|
|
|
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph as RichTextParagraph; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class TextStyle |
|
24
|
|
|
*/ |
|
25
|
|
|
class TextStyle |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $bodyStyle = array(); |
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $titleStyle = array(); |
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $otherStyle = array(); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* TextStyle constructor. |
|
42
|
|
|
* @param bool $default |
|
43
|
|
|
*/ |
|
44
|
198 |
|
public function __construct($default = true) |
|
45
|
|
|
{ |
|
46
|
198 |
|
if ($default) { |
|
47
|
198 |
|
$oRTParagraph = new RichTextParagraph(); |
|
48
|
198 |
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
|
49
|
198 |
|
$oRTParagraph->getFont()->setSize(44)->setColor(new SchemeColor())->getColor()->setValue("lt1"); |
|
|
|
|
|
|
50
|
198 |
|
$this->titleStyle[1] = $oRTParagraph; |
|
51
|
198 |
|
$oRTParagraph = new RichTextParagraph(); |
|
52
|
198 |
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER) |
|
53
|
198 |
|
->setIndent(-324900 / 9525) |
|
54
|
198 |
|
->setMarginLeft(342900 / 9525); |
|
55
|
198 |
|
$oRTParagraph->getFont()->setSize(32)->setColor(new SchemeColor())->getColor()->setValue("tx1"); |
|
|
|
|
|
|
56
|
198 |
|
$this->bodyStyle[1] = $oRTParagraph; |
|
57
|
198 |
|
$oRTParagraph = new RichTextParagraph(); |
|
58
|
198 |
|
$oRTParagraph->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); |
|
59
|
198 |
|
$oRTParagraph->getFont()->setSize(10)->setColor(new SchemeColor())->getColor()->setValue("tx1"); |
|
|
|
|
|
|
60
|
198 |
|
$this->otherStyle[0] = $oRTParagraph; |
|
61
|
|
|
} |
|
62
|
198 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $lvl |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
4 |
|
private function checkLvl($lvl) |
|
69
|
|
|
{ |
|
70
|
4 |
|
if (!is_int($lvl)) { |
|
71
|
4 |
|
return false; |
|
72
|
|
|
} |
|
73
|
3 |
|
if ($lvl > 9) { |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
3 |
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param RichTextParagraph $style |
|
81
|
|
|
* @param $lvl |
|
82
|
|
|
*/ |
|
83
|
4 |
|
public function setBodyStyleAtLvl(RichTextParagraph $style, $lvl) |
|
84
|
|
|
{ |
|
85
|
4 |
|
if (!$this->checkLvl($lvl)) { |
|
86
|
4 |
|
$this->bodyStyle[$lvl] = $style; |
|
87
|
|
|
} |
|
88
|
4 |
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param RichTextParagraph $style |
|
92
|
|
|
* @param $lvl |
|
93
|
|
|
*/ |
|
94
|
4 |
|
public function setTitleStyleAtLvl(RichTextParagraph $style, $lvl) |
|
95
|
|
|
{ |
|
96
|
4 |
|
if (!$this->checkLvl($lvl)) { |
|
97
|
4 |
|
$this->titleStyle[$lvl] = $style; |
|
98
|
|
|
} |
|
99
|
4 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param RichTextParagraph $style |
|
103
|
|
|
* @param $lvl |
|
104
|
|
|
*/ |
|
105
|
4 |
|
public function setOtherStyleAtLvl(RichTextParagraph $style, $lvl) |
|
106
|
|
|
{ |
|
107
|
4 |
|
if (!$this->checkLvl($lvl)) { |
|
108
|
4 |
|
$this->otherStyle[$lvl] = $style; |
|
109
|
|
|
} |
|
110
|
4 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param $lvl |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getBodyStyleAtLvl($lvl) |
|
117
|
|
|
{ |
|
118
|
|
|
if (!$this->checkLvl($lvl)) { |
|
119
|
|
|
return $this->bodyStyle[$lvl]; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param $lvl |
|
125
|
|
|
* @return mixed |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getTitleStyleAtLvl($lvl) |
|
128
|
|
|
{ |
|
129
|
|
|
if (!$this->checkLvl($lvl)) { |
|
130
|
|
|
return $this->bodyStyle[$lvl]; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param $lvl |
|
136
|
|
|
* @return mixed |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getOtherStyleAtLvl($lvl) |
|
139
|
|
|
{ |
|
140
|
|
|
if (!$this->checkLvl($lvl)) { |
|
141
|
|
|
return $this->bodyStyle[$lvl]; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return array |
|
147
|
|
|
*/ |
|
148
|
95 |
|
public function getBodyStyle() |
|
149
|
|
|
{ |
|
150
|
95 |
|
return $this->bodyStyle; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return array |
|
155
|
|
|
*/ |
|
156
|
95 |
|
public function getTitleStyle() |
|
157
|
|
|
{ |
|
158
|
95 |
|
return $this->titleStyle; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @return array |
|
163
|
|
|
*/ |
|
164
|
95 |
|
public function getOtherStyle() |
|
165
|
|
|
{ |
|
166
|
95 |
|
return $this->otherStyle; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: