2014-04-25 10:33:45 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-04-25 10:33:45 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-04-25 10:33:45 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
|
|
|
|
|
2014-05-07 09:47:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\AbstractElement as Element;
|
|
|
|
|
use PhpOffice\PhpWord\Exception\Exception;
|
2014-05-12 22:55:06 +07:00
|
|
|
use PhpOffice\PhpWord\Shared\String;
|
2014-04-25 10:33:45 +07:00
|
|
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-07 09:47:02 +07:00
|
|
|
* Abstract element writer
|
2014-04-25 10:33:45 +07:00
|
|
|
*
|
2014-05-09 14:57:06 +07:00
|
|
|
* @since 0.11.0
|
2014-04-25 10:33:45 +07:00
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
abstract class AbstractElement
|
2014-04-25 10:33:45 +07:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* XML writer
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Shared\XMLWriter
|
|
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
private $xmlWriter;
|
2014-04-25 10:33:45 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Element
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Element\AbstractElement
|
|
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
private $element;
|
2014-04-25 10:33:45 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Without paragraph
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
protected $withoutP = false;
|
|
|
|
|
|
2014-05-07 09:47:02 +07:00
|
|
|
/**
|
|
|
|
|
* Write element
|
|
|
|
|
*/
|
|
|
|
|
abstract public function write();
|
|
|
|
|
|
2014-04-25 10:33:45 +07:00
|
|
|
/**
|
|
|
|
|
* Create new instance
|
|
|
|
|
*
|
|
|
|
|
* @param bool $withoutP
|
|
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false)
|
2014-04-25 10:33:45 +07:00
|
|
|
{
|
|
|
|
|
$this->xmlWriter = $xmlWriter;
|
|
|
|
|
$this->element = $element;
|
|
|
|
|
$this->withoutP = $withoutP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-07 09:47:02 +07:00
|
|
|
* Get XML Writer
|
|
|
|
|
*
|
|
|
|
|
* @return \PhpOffice\PhpWord\Shared\XMLWriter
|
|
|
|
|
*/
|
|
|
|
|
protected function getXmlWriter()
|
|
|
|
|
{
|
|
|
|
|
return $this->xmlWriter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-12 22:55:06 +07:00
|
|
|
* Get element
|
2014-04-25 10:33:45 +07:00
|
|
|
*
|
2014-05-07 09:47:02 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Element\AbstractElement
|
2014-04-25 10:33:45 +07:00
|
|
|
*/
|
2014-05-07 09:47:02 +07:00
|
|
|
protected function getElement()
|
2014-04-25 10:33:45 +07:00
|
|
|
{
|
2014-05-07 09:47:02 +07:00
|
|
|
if (!is_null($this->element)) {
|
2014-05-09 00:28:29 +07:00
|
|
|
return $this->element;
|
2014-05-07 09:47:02 +07:00
|
|
|
} else {
|
|
|
|
|
throw new Exception('No element assigned.');
|
2014-04-25 10:33:45 +07:00
|
|
|
}
|
|
|
|
|
}
|
2014-05-12 22:55:06 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert text to valid format
|
|
|
|
|
*
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getText($text)
|
|
|
|
|
{
|
|
|
|
|
return String::controlCharacterPHP2OOXML(htmlspecialchars($text));
|
|
|
|
|
}
|
2014-04-25 10:33:45 +07:00
|
|
|
}
|