60 lines
2.2 KiB
PHP
Raw Normal View History

2014-05-07 09:47:02 +07:00
<?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
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
/**
* Container element writer (section, textrun, header, footnote, cell, etc.)
*
* @since 0.11.0
*/
class Container extends AbstractElement
{
/**
* Write element
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
2014-05-08 19:25:29 +07:00
$container = $this->getElement();
2014-05-07 09:47:02 +07:00
// Loop through subelements
2014-05-08 19:25:29 +07:00
$containerClass = basename(get_class($container));
$subelements = $container->getElements();
2014-05-08 12:58:44 +07:00
$withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote', 'TextBox')) ? true : false;
2014-05-07 09:47:02 +07:00
if (count($subelements) > 0) {
foreach ($subelements as $subelement) {
2014-05-08 19:25:29 +07:00
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' .
basename(get_class($subelement));
2014-05-07 09:47:02 +07:00
if (class_exists($writerClass)) {
$writer = new $writerClass($xmlWriter, $subelement, $withoutP);
$writer->write();
}
}
} else {
// Special case for Cell: They have to contain a TextBreak at least
if ($containerClass == 'Cell') {
2014-05-08 19:25:29 +07:00
$writerClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\TextBreak';
2014-05-07 09:47:02 +07:00
$writer = new $writerClass($xmlWriter, new TextBreakElement(), $withoutP);
$writer->write();
}
}
}
}