Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Meta | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| read | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
6 | |||
| 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\Reader\ODText; |
| 20 | |
| 21 | use PhpOffice\PhpWord\PhpWord; |
| 22 | use PhpOffice\PhpWord\Shared\XMLReader; |
| 23 | |
| 24 | /** |
| 25 | * Meta reader. |
| 26 | * |
| 27 | * @since 0.11.0 |
| 28 | */ |
| 29 | class Meta extends AbstractPart |
| 30 | { |
| 31 | /** |
| 32 | * Read meta.xml. |
| 33 | * |
| 34 | * @todo Process property type |
| 35 | */ |
| 36 | public function read(PhpWord $phpWord): void |
| 37 | { |
| 38 | $xmlReader = new XMLReader(); |
| 39 | $xmlReader->getDomFromZip($this->docFile, $this->xmlFile); |
| 40 | $docProps = $phpWord->getDocInfo(); |
| 41 | |
| 42 | $metaNode = $xmlReader->getElement('office:meta'); |
| 43 | |
| 44 | // Standard properties |
| 45 | $properties = [ |
| 46 | 'title' => 'dc:title', |
| 47 | 'subject' => 'dc:subject', |
| 48 | 'description' => 'dc:description', |
| 49 | 'keywords' => 'meta:keyword', |
| 50 | 'creator' => 'meta:initial-creator', |
| 51 | 'lastModifiedBy' => 'dc:creator', |
| 52 | // 'created' => 'meta:creation-date', |
| 53 | // 'modified' => 'dc:date', |
| 54 | ]; |
| 55 | foreach ($properties as $property => $path) { |
| 56 | $method = "set{$property}"; |
| 57 | $propertyNode = $xmlReader->getElement($path, $metaNode); |
| 58 | if ($propertyNode !== null && method_exists($docProps, $method)) { |
| 59 | $docProps->$method($propertyNode->nodeValue); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Custom properties |
| 64 | $propertyNodes = $xmlReader->getElements('meta:user-defined', $metaNode); |
| 65 | foreach ($propertyNodes as $propertyNode) { |
| 66 | $property = $xmlReader->getAttribute('meta:name', $propertyNode); |
| 67 | |
| 68 | // Set category, company, and manager property |
| 69 | if (in_array($property, ['Category', 'Company', 'Manager'])) { |
| 70 | $method = "set{$property}"; |
| 71 | $docProps->$method($propertyNode->nodeValue); |
| 72 | } else { |
| 73 | // Set other custom properties |
| 74 | $docProps->setCustomProperty($property, $propertyNode->nodeValue); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |