PHPWord/src/PhpWord/Writer/Word2007/Element/AbstractElement.php

105 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
* 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.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
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;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
2014-05-07 09:47:02 +07:00
* Abstract element writer
*
* @since 0.11.0
*/
2014-05-07 09:47:02 +07:00
abstract class AbstractElement
{
/**
* XML writer
*
* @var \PhpOffice\PhpWord\Shared\XMLWriter
*/
2014-05-07 09:47:02 +07:00
private $xmlWriter;
/**
* Element
*
* @var \PhpOffice\PhpWord\Element\AbstractElement
*/
2014-05-07 09:47:02 +07:00
private $element;
/**
* Without paragraph
*
* @var bool
*/
protected $withoutP = false;
2014-05-07 09:47:02 +07:00
/**
* Write element
*/
abstract public function write();
/**
* Create new instance
*
* @param bool $withoutP
*/
2014-05-07 09:47:02 +07:00
public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false)
{
$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;
}
/**
* Get element
*
2014-05-07 09:47:02 +07:00
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
2014-05-07 09:47:02 +07:00
protected function getElement()
{
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.');
}
}
/**
* Convert text to valid format
*
* @param string $text
* @return string
*/
protected function getText($text)
{
return String::controlCharacterPHP2OOXML(htmlspecialchars($text));
}
}