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-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
|
|
|
*
|
|
|
|
|
* @since 0.10.0
|
|
|
|
|
*/
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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)) {
|
|
|
|
|
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . basename(get_class($this->element));
|
|
|
|
|
if ($this->element instanceof $elementClass) {
|
|
|
|
|
return $this->element;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('No valid element assigned.');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception('No element assigned.');
|
2014-04-25 10:33:45 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|