Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Link | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFontStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParagraphStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isInternal | |
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 | * Link element. |
26 | */ |
27 | class Link extends AbstractElement |
28 | { |
29 | /** |
30 | * Link source. |
31 | * |
32 | * @var string |
33 | */ |
34 | private $source; |
35 | |
36 | /** |
37 | * Link text. |
38 | * |
39 | * @var string |
40 | */ |
41 | private $text; |
42 | |
43 | /** |
44 | * Font style. |
45 | * |
46 | * @var null|\PhpOffice\PhpWord\Style\Font|string |
47 | */ |
48 | private $fontStyle; |
49 | |
50 | /** |
51 | * Paragraph style. |
52 | * |
53 | * @var null|\PhpOffice\PhpWord\Style\Paragraph|string |
54 | */ |
55 | private $paragraphStyle; |
56 | |
57 | /** |
58 | * Has media relation flag; true for Link, Image, and Object. |
59 | * |
60 | * @var bool |
61 | */ |
62 | protected $mediaRelation = true; |
63 | |
64 | /** |
65 | * Has internal flag - anchor to internal bookmark. |
66 | * |
67 | * @var bool |
68 | */ |
69 | protected $internal = false; |
70 | |
71 | /** |
72 | * Create a new Link Element. |
73 | * |
74 | * @param string $source |
75 | * @param string $text |
76 | * @param mixed $fontStyle |
77 | * @param mixed $paragraphStyle |
78 | * @param bool $internal |
79 | */ |
80 | public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false) |
81 | { |
82 | $this->source = SharedText::toUTF8($source); |
83 | $this->text = null === $text ? $this->source : SharedText::toUTF8($text); |
84 | $this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle); |
85 | $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); |
86 | $this->internal = $internal; |
87 | } |
88 | |
89 | /** |
90 | * Get link source. |
91 | * |
92 | * @return string |
93 | */ |
94 | public function getSource() |
95 | { |
96 | return $this->source; |
97 | } |
98 | |
99 | /** |
100 | * Get link text. |
101 | * |
102 | * @return string |
103 | */ |
104 | public function getText() |
105 | { |
106 | return $this->text; |
107 | } |
108 | |
109 | /** |
110 | * Get Text style. |
111 | * |
112 | * @return null|\PhpOffice\PhpWord\Style\Font|string |
113 | */ |
114 | public function getFontStyle() |
115 | { |
116 | return $this->fontStyle; |
117 | } |
118 | |
119 | /** |
120 | * Get Paragraph style. |
121 | * |
122 | * @return null|\PhpOffice\PhpWord\Style\Paragraph|string |
123 | */ |
124 | public function getParagraphStyle() |
125 | { |
126 | return $this->paragraphStyle; |
127 | } |
128 | |
129 | /** |
130 | * is internal. |
131 | * |
132 | * @return bool |
133 | */ |
134 | public function isInternal() |
135 | { |
136 | return $this->internal; |
137 | } |
138 | } |