Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Writer\Word2007\Part;
  18. use PhpOffice\PhpWord\Exception\Exception;
  19. use PhpOffice\PhpWord\Shared\XMLWriter;
  20. use PhpOffice\PhpWord\Writer\AbstractWriter;
  21. /**
  22. * Word2007 writer part abstract class
  23. */
  24. abstract class AbstractPart
  25. {
  26. /**
  27. * Parent writer
  28. *
  29. * @var \PhpOffice\PhpWord\Writer\AbstractWriter
  30. */
  31. protected $parentWriter;
  32. /**
  33. * @var string Date format
  34. */
  35. protected $dateFormat = 'Y-m-d\TH:i:sP';
  36. /**
  37. * Write part
  38. *
  39. * @return string
  40. */
  41. abstract public function write();
  42. /**
  43. * Set parent writer.
  44. *
  45. * @param \PhpOffice\PhpWord\Writer\AbstractWriter $writer
  46. * @return void
  47. */
  48. public function setParentWriter(AbstractWriter $writer = null)
  49. {
  50. $this->parentWriter = $writer;
  51. }
  52. /**
  53. * Get parent writer
  54. *
  55. * @return \PhpOffice\PhpWord\Writer\AbstractWriter
  56. * @throws \PhpOffice\PhpWord\Exception\Exception
  57. */
  58. public function getParentWriter()
  59. {
  60. if (!is_null($this->parentWriter)) {
  61. return $this->parentWriter;
  62. } else {
  63. throw new Exception('No parent WriterInterface assigned.');
  64. }
  65. }
  66. /**
  67. * Get XML Writer
  68. *
  69. * @return \PhpOffice\PhpWord\Shared\XMLWriter
  70. */
  71. protected function getXmlWriter()
  72. {
  73. $useDiskCaching = false;
  74. if (!is_null($this->parentWriter)) {
  75. if ($this->parentWriter->isUseDiskCaching()) {
  76. $useDiskCaching = true;
  77. }
  78. }
  79. if ($useDiskCaching) {
  80. return new XMLWriter(XMLWriter::STORAGE_DISK, $this->parentWriter->getDiskCachingDirectory());
  81. } else {
  82. return new XMLWriter(XMLWriter::STORAGE_MEMORY);
  83. }
  84. }
  85. }