Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| OLEObject | |
100.00% |
15 / 15 |
|
100.00% |
6 / 6 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
10 / 10 |
|
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 | /** |
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | * word processing documents. |
| 6 | * |
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | * General Public License version 3 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * For the full copyright and license information, please read the LICENSE |
| 11 | * file that was distributed with this source code. For the full list of |
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | * |
| 14 | * @see https://github.com/PHPOffice/PHPWord |
| 15 | * |
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | */ |
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Element; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Exception\InvalidObjectException; |
| 22 | use PhpOffice\PhpWord\Style\Image as ImageStyle; |
| 23 | |
| 24 | /** |
| 25 | * OLEObject element. |
| 26 | */ |
| 27 | class OLEObject extends AbstractElement |
| 28 | { |
| 29 | /** |
| 30 | * Ole-Object Src. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | private $source; |
| 35 | |
| 36 | /** |
| 37 | * Image Style. |
| 38 | * |
| 39 | * @var ?ImageStyle |
| 40 | */ |
| 41 | private $style; |
| 42 | |
| 43 | /** |
| 44 | * Icon. |
| 45 | * |
| 46 | * @var string |
| 47 | */ |
| 48 | private $icon; |
| 49 | |
| 50 | /** |
| 51 | * Image Relation ID. |
| 52 | * |
| 53 | * @var int |
| 54 | */ |
| 55 | private $imageRelationId; |
| 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 | * Create a new Ole-Object Element. |
| 66 | * |
| 67 | * @param string $source |
| 68 | * @param mixed $style |
| 69 | */ |
| 70 | public function __construct($source, $style = null) |
| 71 | { |
| 72 | $supportedTypes = ['xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx']; |
| 73 | $pathInfoExtension = pathinfo($source, PATHINFO_EXTENSION); |
| 74 | |
| 75 | if (file_exists($source) && in_array($pathInfoExtension, $supportedTypes)) { |
| 76 | if (strlen($pathInfoExtension) == 4 && strtolower(substr($pathInfoExtension, -1)) == 'x') { |
| 77 | $pathInfoExtension = substr($pathInfoExtension, 0, -1); |
| 78 | } |
| 79 | |
| 80 | $this->source = $source; |
| 81 | $this->style = $this->setNewStyle(new ImageStyle(), $style, true); |
| 82 | $this->icon = realpath(__DIR__ . "/../resources/{$pathInfoExtension}.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 ?ImageStyle |
| 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 | } |