Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
PreserveText | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
getFontStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParagraphStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord 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/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Element; |
19 | |
20 | use PhpOffice\PhpWord\Shared\Text as SharedText; |
21 | use PhpOffice\PhpWord\Style\Font; |
22 | use PhpOffice\PhpWord\Style\Paragraph; |
23 | |
24 | /** |
25 | * Preserve text/field element. |
26 | */ |
27 | class PreserveText extends AbstractElement |
28 | { |
29 | /** |
30 | * Text content. |
31 | * |
32 | * @var null|array|string |
33 | */ |
34 | private $text; |
35 | |
36 | /** |
37 | * Text style. |
38 | * |
39 | * @var null|\PhpOffice\PhpWord\Style\Font|string |
40 | */ |
41 | private $fontStyle; |
42 | |
43 | /** |
44 | * Paragraph style. |
45 | * |
46 | * @var null|\PhpOffice\PhpWord\Style\Paragraph|string |
47 | */ |
48 | private $paragraphStyle; |
49 | |
50 | /** |
51 | * Create a new Preserve Text Element. |
52 | * |
53 | * @param string $text |
54 | * @param mixed $fontStyle |
55 | * @param mixed $paragraphStyle |
56 | */ |
57 | public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) |
58 | { |
59 | $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); |
60 | $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); |
61 | |
62 | $this->text = SharedText::toUTF8($text); |
63 | $matches = preg_split('/({.*?})/', $this->text ?? '', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
64 | if (isset($matches[0])) { |
65 | $this->text = $matches; |
66 | } |
67 | } |
68 | |
69 | /** |
70 | * Get Text style. |
71 | * |
72 | * @return null|\PhpOffice\PhpWord\Style\Font|string |
73 | */ |
74 | public function getFontStyle() |
75 | { |
76 | return $this->fontStyle; |
77 | } |
78 | |
79 | /** |
80 | * Get Paragraph style. |
81 | * |
82 | * @return null|\PhpOffice\PhpWord\Style\Paragraph|string |
83 | */ |
84 | public function getParagraphStyle() |
85 | { |
86 | return $this->paragraphStyle; |
87 | } |
88 | |
89 | /** |
90 | * Get Text content. |
91 | * |
92 | * @return null|array|string |
93 | */ |
94 | public function getText() |
95 | { |
96 | return $this->text; |
97 | } |
98 | } |