Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
DocPropsCore
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 write
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
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
18namespace PhpOffice\PhpWord\Writer\Word2007\Part;
19
20/**
21 * Word2007 core document properties part writer: docProps/core.xml.
22 *
23 * @since 0.11.0
24 */
25class DocPropsCore extends AbstractPart
26{
27    /**
28     * Write part.
29     *
30     * @return string
31     */
32    public function write()
33    {
34        $phpWord = $this->getParentWriter()->getPhpWord();
35        $xmlWriter = $this->getXmlWriter();
36        $schema = 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties';
37
38        $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
39        $xmlWriter->startElement('cp:coreProperties');
40        $xmlWriter->writeAttribute('xmlns:cp', $schema);
41        $xmlWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
42        $xmlWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
43        $xmlWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
44        $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
45
46        $xmlWriter->writeElement('dc:creator', $phpWord->getDocInfo()->getCreator());
47        $xmlWriter->writeElement('dc:title', $phpWord->getDocInfo()->getTitle());
48        $xmlWriter->writeElement('dc:description', $phpWord->getDocInfo()->getDescription());
49        $xmlWriter->writeElement('dc:subject', $phpWord->getDocInfo()->getSubject());
50        $xmlWriter->writeElement('cp:keywords', $phpWord->getDocInfo()->getKeywords());
51        $xmlWriter->writeElement('cp:category', $phpWord->getDocInfo()->getCategory());
52        $xmlWriter->writeElement('cp:lastModifiedBy', $phpWord->getDocInfo()->getLastModifiedBy());
53
54        // dcterms:created
55        $xmlWriter->startElement('dcterms:created');
56        $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
57        $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getCreated()));
58        $xmlWriter->endElement();
59
60        // dcterms:modified
61        $xmlWriter->startElement('dcterms:modified');
62        $xmlWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
63        $xmlWriter->text(date($this->dateFormat, $phpWord->getDocInfo()->getModified()));
64        $xmlWriter->endElement();
65
66        $xmlWriter->endElement(); // cp:coreProperties
67
68        return $xmlWriter->getData();
69    }
70}