Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
DocPropsCustom | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
read | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 |
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\Reader\Word2007; |
19 | |
20 | use PhpOffice\PhpWord\Metadata\DocInfo; |
21 | use PhpOffice\PhpWord\PhpWord; |
22 | use PhpOffice\PhpWord\Shared\XMLReader; |
23 | |
24 | /** |
25 | * Custom properties reader. |
26 | * |
27 | * @since 0.11.0 |
28 | */ |
29 | class DocPropsCustom extends AbstractPart |
30 | { |
31 | /** |
32 | * Read custom document properties. |
33 | */ |
34 | public function read(PhpWord $phpWord): void |
35 | { |
36 | $xmlReader = new XMLReader(); |
37 | $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); |
38 | $docProps = $phpWord->getDocInfo(); |
39 | |
40 | $nodes = $xmlReader->getElements('*'); |
41 | if ($nodes->length > 0) { |
42 | foreach ($nodes as $node) { |
43 | $propertyName = $xmlReader->getAttribute('name', $node); |
44 | $attributeNode = $xmlReader->getElement('*', $node); |
45 | $attributeType = $attributeNode->nodeName; |
46 | $attributeValue = $attributeNode->nodeValue; |
47 | $attributeValue = DocInfo::convertProperty($attributeValue, $attributeType); |
48 | $attributeType = DocInfo::convertPropertyType($attributeType); |
49 | $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType); |
50 | } |
51 | } |
52 | } |
53 | } |