Reduce duplications and fix some docblocks
This commit is contained in:
parent
479713da55
commit
d97602fa98
@ -188,6 +188,7 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Set relation Id
|
* Set relation Id
|
||||||
*
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
|
||||||
* @param string $elementName
|
* @param string $elementName
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -66,6 +66,7 @@ class Table extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Write column
|
* Write column
|
||||||
*
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\Row $row
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function writeRowDef(RowElement $row)
|
private function writeRowDef(RowElement $row)
|
||||||
@ -89,6 +90,7 @@ class Table extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Write row
|
* Write row
|
||||||
*
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\Row $row
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function writeRow(RowElement $row)
|
private function writeRow(RowElement $row)
|
||||||
@ -106,6 +108,7 @@ class Table extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Write cell
|
* Write cell
|
||||||
*
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\Cell $cell
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function writeCell(CellElement $cell)
|
private function writeCell(CellElement $cell)
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Element\AbstractElement as Element;
|
use PhpOffice\PhpWord\Element\AbstractElement as Element;
|
||||||
|
use PhpOffice\PhpWord\Element\PageBreak as PageBreakElement;
|
||||||
use PhpOffice\PhpWord\Shared\String;
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
use PhpOffice\PhpWord\Shared\XMLWriter;
|
use PhpOffice\PhpWord\Shared\XMLWriter;
|
||||||
|
|
||||||
@ -116,7 +117,28 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write ending
|
* Start w:p DOM element
|
||||||
|
*
|
||||||
|
* @uses \PhpOffice\PhpWord\Writer\Word2007\Element\PageBreak::write()
|
||||||
|
*/
|
||||||
|
protected function startElementP()
|
||||||
|
{
|
||||||
|
if (!$this->withoutP) {
|
||||||
|
$this->xmlWriter->startElement('w:p');
|
||||||
|
// Paragraph style
|
||||||
|
if (method_exists($this->element, 'getParagraphStyle')) {
|
||||||
|
$this->writeParagraphStyle();
|
||||||
|
}
|
||||||
|
// PageBreak
|
||||||
|
if ($this->pageBreakBefore) {
|
||||||
|
$elementWriter = new PageBreak($this->xmlWriter, new PageBreakElement());
|
||||||
|
$elementWriter->write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End w:p DOM element
|
||||||
*/
|
*/
|
||||||
protected function endElementP()
|
protected function endElementP()
|
||||||
{
|
{
|
||||||
@ -125,6 +147,43 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write ending
|
||||||
|
*/
|
||||||
|
protected function writeParagraphStyle()
|
||||||
|
{
|
||||||
|
$this->writeTextStyle('Paragraph');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write ending
|
||||||
|
*/
|
||||||
|
protected function writeFontStyle()
|
||||||
|
{
|
||||||
|
$this->writeTextStyle('Font');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write text style
|
||||||
|
*
|
||||||
|
* @param string $styleType Font|Paragraph
|
||||||
|
*/
|
||||||
|
private function writeTextStyle($styleType)
|
||||||
|
{
|
||||||
|
$method = "get{$styleType}Style";
|
||||||
|
$class = "PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\{$styleType}";
|
||||||
|
$styleObject = $this->element->$method();
|
||||||
|
|
||||||
|
$styleWriter = new $class($this->xmlWriter, $styleObject);
|
||||||
|
if (method_exists($styleWriter, 'setIsInline')) {
|
||||||
|
$styleWriter->setIsInline(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle $styleWriter */
|
||||||
|
$styleWriter->write();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert text to valid format
|
* Convert text to valid format
|
||||||
*
|
*
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class CheckBox extends Text
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:fldChar');
|
$xmlWriter->startElement('w:fldChar');
|
||||||
|
|||||||
@ -67,7 +67,8 @@ class Field extends Text
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:fldSimple');
|
$xmlWriter->startElement('w:fldSimple');
|
||||||
$xmlWriter->writeAttribute('w:instr', $instruction);
|
$xmlWriter->writeAttribute('w:instr', $instruction);
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class Footnote extends Text
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
$xmlWriter->startElement('w:rPr');
|
$xmlWriter->startElement('w:rPr');
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class Link extends Text
|
|||||||
|
|
||||||
$rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0);
|
$rId = $element->getRelationId() + ($element->isInSection() ? 6 : 0);
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:hyperlink');
|
$xmlWriter->startElement('w:hyperlink');
|
||||||
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class PageBreak extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Write element
|
* Write element
|
||||||
*
|
*
|
||||||
* @usedby \PhpOffice\PhpWord\Writer\Word2007\Element\Text::writeOpeningWP()
|
* @usedby \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement::startElementP()
|
||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class PreserveText extends Text
|
|||||||
$texts = array($texts);
|
$texts = array($texts);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
foreach ($texts as $text) {
|
foreach ($texts as $text) {
|
||||||
if (substr($text, 0, 1) == '{') {
|
if (substr($text, 0, 1) == '{') {
|
||||||
|
|||||||
@ -17,10 +17,6 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Element\PageBreak as PageBreakElement;
|
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
|
|
||||||
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text element writer
|
* Text element writer
|
||||||
*
|
*
|
||||||
@ -39,7 +35,7 @@ class Text extends AbstractElement
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$xmlWriter->startElement('w:r');
|
$xmlWriter->startElement('w:r');
|
||||||
|
|
||||||
@ -53,58 +49,4 @@ class Text extends AbstractElement
|
|||||||
|
|
||||||
$this->endElementP(); // w:p
|
$this->endElementP(); // w:p
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Write opening
|
|
||||||
*
|
|
||||||
* @uses \PhpOffice\PhpWord\Writer\Word2007\Element\PageBreak::write()
|
|
||||||
*/
|
|
||||||
protected function writeOpeningWP()
|
|
||||||
{
|
|
||||||
$xmlWriter = $this->getXmlWriter();
|
|
||||||
$element = $this->getElement();
|
|
||||||
|
|
||||||
if (!$this->withoutP) {
|
|
||||||
$xmlWriter->startElement('w:p');
|
|
||||||
// Paragraph style
|
|
||||||
if (method_exists($element, 'getParagraphStyle')) {
|
|
||||||
$this->writeParagraphStyle();
|
|
||||||
}
|
|
||||||
// PageBreak
|
|
||||||
if ($this->hasPageBreakBefore()) {
|
|
||||||
$elementWriter = new PageBreak($xmlWriter, new PageBreakElement());
|
|
||||||
$elementWriter->write();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write ending
|
|
||||||
*/
|
|
||||||
protected function writeParagraphStyle()
|
|
||||||
{
|
|
||||||
$xmlWriter = $this->getXmlWriter();
|
|
||||||
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
|
|
||||||
$element = $this->getElement();
|
|
||||||
$paragraphStyle = $element->getParagraphStyle();
|
|
||||||
$styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle);
|
|
||||||
$styleWriter->setIsInline(true);
|
|
||||||
$styleWriter->write();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write ending
|
|
||||||
*/
|
|
||||||
protected function writeFontStyle()
|
|
||||||
{
|
|
||||||
$xmlWriter = $this->getXmlWriter();
|
|
||||||
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
|
|
||||||
$element = $this->getElement();
|
|
||||||
$fontStyle = $element->getFontStyle();
|
|
||||||
$styleWriter = new FontStyleWriter($xmlWriter, $fontStyle);
|
|
||||||
$styleWriter->setIsInline(true);
|
|
||||||
$styleWriter->write();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class TextBreak extends Text
|
|||||||
|
|
||||||
if (!$this->withoutP) {
|
if (!$this->withoutP) {
|
||||||
$hasStyle = $element->hasStyle();
|
$hasStyle = $element->hasStyle();
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
if ($hasStyle) {
|
if ($hasStyle) {
|
||||||
$xmlWriter->startElement('w:pPr');
|
$xmlWriter->startElement('w:pPr');
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class TextRun extends Text
|
|||||||
$xmlWriter = $this->getXmlWriter();
|
$xmlWriter = $this->getXmlWriter();
|
||||||
$element = $this->getElement();
|
$element = $this->getElement();
|
||||||
|
|
||||||
$this->writeOpeningWP();
|
$this->startElementP();
|
||||||
|
|
||||||
$containerWriter = new Container($xmlWriter, $element);
|
$containerWriter = new Container($xmlWriter, $element);
|
||||||
$containerWriter->write();
|
$containerWriter->write();
|
||||||
|
|||||||
@ -134,6 +134,7 @@ class Frame extends AbstractStyle
|
|||||||
/**
|
/**
|
||||||
* Get style values in associative array
|
* Get style values in associative array
|
||||||
*
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Style\Frame $style
|
||||||
* @param array $properties
|
* @param array $properties
|
||||||
* @param string $suffix
|
* @param string $suffix
|
||||||
* @return array
|
* @return array
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user