Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WPS | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| save | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 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; |
| 20 | |
| 21 | use PhpOffice\Common\Microsoft\OLEWrite; |
| 22 | use PhpOffice\PhpWord\PhpWord; |
| 23 | |
| 24 | /** |
| 25 | * WPS writer, Microsoft Works word processor. |
| 26 | * |
| 27 | * The document is an OLE compound file whose CONTENTS stream holds the |
| 28 | * chunked (CHNKWKS) representation of the document. |
| 29 | * |
| 30 | * @since 1.5.0 |
| 31 | */ |
| 32 | class WPS extends AbstractWriter implements WriterInterface |
| 33 | { |
| 34 | /** |
| 35 | * Create new instance. |
| 36 | */ |
| 37 | public function __construct(?PhpWord $phpWord = null) |
| 38 | { |
| 39 | $this->setPhpWord($phpWord); |
| 40 | |
| 41 | $this->parts = ['Contents']; |
| 42 | foreach ($this->parts as $partName) { |
| 43 | $partClass = static::class . '\\Part\\' . $partName; |
| 44 | if (class_exists($partClass)) { |
| 45 | /** @var WPS\Part\AbstractPart $part */ |
| 46 | $part = new $partClass(); |
| 47 | $part->setParentWriter($this); |
| 48 | $this->writerParts[strtolower($partName)] = $part; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Save content to file. |
| 55 | */ |
| 56 | public function save(string $filename): void |
| 57 | { |
| 58 | $ole = new OLEWrite(); |
| 59 | $ole->addStream('CONTENTS', $this->getWriterPart('Contents')->write()); |
| 60 | |
| 61 | $this->writeFile($this->openFile($filename), $ole->write()); |
| 62 | } |
| 63 | } |