Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
OLEObject | |
100.00% |
16 / 16 |
|
100.00% |
6 / 6 |
10 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |||
getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getStyle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIcon | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getImageRelationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setImageRelationId | |
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\Exception\InvalidObjectException; |
21 | use PhpOffice\PhpWord\Style\Image as ImageStyle; |
22 | |
23 | /** |
24 | * OLEObject element. |
25 | */ |
26 | class OLEObject extends AbstractElement |
27 | { |
28 | /** |
29 | * Ole-Object Src. |
30 | * |
31 | * @var string |
32 | */ |
33 | private $source; |
34 | |
35 | /** |
36 | * Image Style. |
37 | * |
38 | * @var ?\PhpOffice\PhpWord\Style\Image |
39 | */ |
40 | private $style; |
41 | |
42 | /** |
43 | * Icon. |
44 | * |
45 | * @var string |
46 | */ |
47 | private $icon; |
48 | |
49 | /** |
50 | * Image Relation ID. |
51 | * |
52 | * @var int |
53 | */ |
54 | private $imageRelationId; |
55 | |
56 | /** |
57 | * Has media relation flag; true for Link, Image, and Object. |
58 | * |
59 | * @var bool |
60 | */ |
61 | protected $mediaRelation = true; |
62 | |
63 | /** |
64 | * Create a new Ole-Object Element. |
65 | * |
66 | * @param string $source |
67 | * @param mixed $style |
68 | */ |
69 | public function __construct($source, $style = null) |
70 | { |
71 | $supportedTypes = ['xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx']; |
72 | $pathInfo = pathinfo($source); |
73 | |
74 | if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) { |
75 | $ext = $pathInfo['extension']; |
76 | if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') { |
77 | $ext = substr($ext, 0, -1); |
78 | } |
79 | |
80 | $this->source = $source; |
81 | $this->style = $this->setNewStyle(new ImageStyle(), $style, true); |
82 | $this->icon = realpath(__DIR__ . "/../resources/{$ext}.png"); |
83 | |
84 | return; |
85 | } |
86 | |
87 | throw new InvalidObjectException(); |
88 | } |
89 | |
90 | /** |
91 | * Get object source. |
92 | * |
93 | * @return string |
94 | */ |
95 | public function getSource() |
96 | { |
97 | return $this->source; |
98 | } |
99 | |
100 | /** |
101 | * Get object style. |
102 | * |
103 | * @return ?\PhpOffice\PhpWord\Style\Image |
104 | */ |
105 | public function getStyle() |
106 | { |
107 | return $this->style; |
108 | } |
109 | |
110 | /** |
111 | * Get object icon. |
112 | * |
113 | * @return string |
114 | */ |
115 | public function getIcon() |
116 | { |
117 | return $this->icon; |
118 | } |
119 | |
120 | /** |
121 | * Get image relation ID. |
122 | * |
123 | * @return int |
124 | */ |
125 | public function getImageRelationId() |
126 | { |
127 | return $this->imageRelationId; |
128 | } |
129 | |
130 | /** |
131 | * Set Image Relation ID. |
132 | * |
133 | * @param int $rId |
134 | */ |
135 | public function setImageRelationId($rId): void |
136 | { |
137 | $this->imageRelationId = $rId; |
138 | } |
139 | } |