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