Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Manifest | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| write | |
100.00% |
35 / 35 |
|
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\Writer\ODText\Part; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Element\Formula; |
| 22 | use PhpOffice\PhpWord\Media; |
| 23 | use PhpOffice\PhpWord\Writer\ODText; |
| 24 | |
| 25 | /** |
| 26 | * ODText manifest part writer: META-INF/manifest.xml. |
| 27 | */ |
| 28 | class Manifest extends AbstractPart |
| 29 | { |
| 30 | /** |
| 31 | * Write part. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | public function write() |
| 36 | { |
| 37 | $xmlWriter = $this->getXmlWriter(); |
| 38 | |
| 39 | $xmlWriter->startDocument('1.0', 'UTF-8'); |
| 40 | $xmlWriter->startElement('manifest:manifest'); |
| 41 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
| 42 | $xmlWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); |
| 43 | |
| 44 | $xmlWriter->startElement('manifest:file-entry'); |
| 45 | $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.text'); |
| 46 | $xmlWriter->writeAttribute('manifest:full-path', '/'); |
| 47 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
| 48 | $xmlWriter->endElement(); |
| 49 | |
| 50 | // Parts |
| 51 | foreach (['content.xml', 'meta.xml', 'styles.xml'] as $part) { |
| 52 | $xmlWriter->startElement('manifest:file-entry'); |
| 53 | $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); |
| 54 | $xmlWriter->writeAttribute('manifest:full-path', $part); |
| 55 | $xmlWriter->endElement(); |
| 56 | } |
| 57 | |
| 58 | // Media files |
| 59 | $media = Media::getElements('section'); |
| 60 | foreach ($media as $medium) { |
| 61 | if ($medium['type'] == 'image') { |
| 62 | $xmlWriter->startElement('manifest:file-entry'); |
| 63 | $xmlWriter->writeAttribute('manifest:media-type', $medium['imageType']); |
| 64 | $xmlWriter->writeAttribute('manifest:full-path', 'Pictures/' . $medium['target']); |
| 65 | $xmlWriter->endElement(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | foreach ($this->getObjects() as $idxObject => $object) { |
| 70 | if ($object instanceof Formula) { |
| 71 | $xmlWriter->startElement('manifest:file-entry'); |
| 72 | $xmlWriter->writeAttribute('manifest:full-path', 'Formula' . $idxObject . '/content.xml'); |
| 73 | $xmlWriter->writeAttribute('manifest:media-type', 'text/xml'); |
| 74 | $xmlWriter->endElement(); |
| 75 | $xmlWriter->startElement('manifest:file-entry'); |
| 76 | $xmlWriter->writeAttribute('manifest:full-path', 'Formula' . $idxObject . '/'); |
| 77 | $xmlWriter->writeAttribute('manifest:version', '1.2'); |
| 78 | $xmlWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.formula'); |
| 79 | $xmlWriter->endElement(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | $xmlWriter->endElement(); // manifest:manifest |
| 84 | |
| 85 | return $xmlWriter->getData(); |
| 86 | } |
| 87 | } |