Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
AbstractPart | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
9 | |
100.00% |
1 / 1 |
write | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
setParentWriter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getParentWriter | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getXmlWriter | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
writeText | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
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 | |
18 | namespace PhpOffice\PhpWord\Writer\Word2007\Part; |
19 | |
20 | use PhpOffice\PhpWord\Exception\Exception; |
21 | use PhpOffice\PhpWord\Settings; |
22 | use PhpOffice\PhpWord\Shared\XMLWriter; |
23 | use PhpOffice\PhpWord\Writer\AbstractWriter; |
24 | |
25 | /** |
26 | * Word2007 writer part abstract class. |
27 | */ |
28 | abstract class AbstractPart |
29 | { |
30 | /** |
31 | * Parent writer. |
32 | * |
33 | * @var \PhpOffice\PhpWord\Writer\AbstractWriter |
34 | */ |
35 | protected $parentWriter; |
36 | |
37 | /** |
38 | * @var string Date format |
39 | */ |
40 | protected $dateFormat = 'Y-m-d\TH:i:sP'; |
41 | |
42 | /** |
43 | * Write part. |
44 | * |
45 | * @return string |
46 | */ |
47 | abstract public function write(); |
48 | |
49 | /** |
50 | * Set parent writer. |
51 | */ |
52 | public function setParentWriter(?AbstractWriter $writer = null): void |
53 | { |
54 | $this->parentWriter = $writer; |
55 | } |
56 | |
57 | /** |
58 | * Get parent writer. |
59 | * |
60 | * @return \PhpOffice\PhpWord\Writer\AbstractWriter |
61 | */ |
62 | public function getParentWriter() |
63 | { |
64 | if (null !== $this->parentWriter) { |
65 | return $this->parentWriter; |
66 | } |
67 | |
68 | throw new Exception('No parent WriterInterface assigned.'); |
69 | } |
70 | |
71 | /** |
72 | * Get XML Writer. |
73 | * |
74 | * @return \PhpOffice\PhpWord\Shared\XMLWriter |
75 | */ |
76 | protected function getXmlWriter() |
77 | { |
78 | $useDiskCaching = false; |
79 | if (null !== $this->parentWriter) { |
80 | if ($this->parentWriter->isUseDiskCaching()) { |
81 | $useDiskCaching = true; |
82 | } |
83 | } |
84 | if ($useDiskCaching) { |
85 | return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory(), Settings::hasCompatibility()); |
86 | } |
87 | |
88 | return new XMLWriter(XMLWriter::STORAGE_MEMORY, './', Settings::hasCompatibility()); |
89 | } |
90 | |
91 | /** |
92 | * Write an XML text, this will call text() or writeRaw() depending on the value of Settings::isOutputEscapingEnabled(). |
93 | * |
94 | * @param string $content The text string to write |
95 | * |
96 | * @return bool Returns true on success or false on failure |
97 | */ |
98 | protected function writeText($content) |
99 | { |
100 | if (Settings::isOutputEscapingEnabled()) { |
101 | return $this->getXmlWriter()->text($content); |
102 | } |
103 | |
104 | return $this->getXmlWriter()->writeRaw($content); |
105 | } |
106 | } |