Merge branch 'cleanup' into develop

This commit is contained in:
Ivan Lanin 2014-05-14 19:48:52 +07:00
commit f9123d2f2e
78 changed files with 234 additions and 115 deletions

View File

@ -416,8 +416,9 @@ class DocumentProperties
{ {
if ($this->isCustomPropertySet($propertyName)) { if ($this->isCustomPropertySet($propertyName)) {
return $this->customProperties[$propertyName]['value']; return $this->customProperties[$propertyName]['value'];
} else {
return null;
} }
} }
/** /**
@ -430,8 +431,9 @@ class DocumentProperties
{ {
if ($this->isCustomPropertySet($propertyName)) { if ($this->isCustomPropertySet($propertyName)) {
return $this->customProperties[$propertyName]['type']; return $this->customProperties[$propertyName]['type'];
} else {
return null;
} }
} }
/** /**

View File

@ -313,6 +313,7 @@ abstract class AbstractContainer extends AbstractElement
* *
* @param string $method * @param string $method
* @return bool * @return bool
* @throws \BadMethodCallException
*/ */
private function checkValidity($method) private function checkValidity($method)
{ {
@ -389,6 +390,7 @@ abstract class AbstractContainer extends AbstractElement
* *
* @param string $src * @param string $src
* @param mixed $style * @param mixed $style
* @return \PhpOffice\PhpWord\Element\Image
* @deprecated 0.9.0 * @deprecated 0.9.0
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
@ -401,6 +403,7 @@ abstract class AbstractContainer extends AbstractElement
* Create textrun element * Create textrun element
* *
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return \PhpOffice\PhpWord\Element\TextRun
* @deprecated 0.10.0 * @deprecated 0.10.0
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
@ -413,6 +416,7 @@ abstract class AbstractContainer extends AbstractElement
* Create footnote element * Create footnote element
* *
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return \PhpOffice\PhpWord\Element\Footnote
* @deprecated 0.10.0 * @deprecated 0.10.0
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */

View File

@ -220,6 +220,7 @@ abstract class AbstractElement
* @param mixed $styleObject Style object * @param mixed $styleObject Style object
* @param mixed $styleValue Style value * @param mixed $styleValue Style value
* @param bool $returnObject Always return object * @param bool $returnObject Always return object
* @return mixed
*/ */
protected function setStyle($styleObject, $styleValue = null, $returnObject = false) protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
{ {

View File

@ -283,6 +283,8 @@ class Image extends AbstractElement
* Check memory image, supported type, image functions, and proportional width/height * Check memory image, supported type, image functions, and proportional width/height
* *
* @param string $source * @param string $source
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/ */
private function checkImage($source) private function checkImage($source)
{ {

View File

@ -58,6 +58,7 @@ class Object extends AbstractElement
* *
* @param string $source * @param string $source
* @param mixed $style * @param mixed $style
* @throws \PhpOffice\PhpWord\Exception\InvalidObjectException
*/ */
public function __construct($source, $style = null) public function __construct($source, $style = null)
{ {

View File

@ -54,7 +54,7 @@ class PreserveText extends AbstractElement
* @param string $text * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return $this * @return self
*/ */
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{ {

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Section as SectionSettings; use PhpOffice\PhpWord\Style\Section as SectionSettings;
/** /**

View File

@ -301,13 +301,13 @@ class PhpWord
/** /**
* Adds a heading style definition to styles.xml * Adds a heading style definition to styles.xml
* *
* @param int $titleCount * @param int $depth
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
*/ */
public function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null) public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
{ {
Style::addTitleStyle($titleCount, $fontStyle, $paragraphStyle); Style::addTitleStyle($depth, $fontStyle, $paragraphStyle);
} }
/** /**

View File

@ -27,6 +27,8 @@ abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractP
/** /**
* Read w:r (override) * Read w:r (override)
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param mixed $parent * @param mixed $parent
* @param string $docPart * @param string $docPart
* @param mixed $paragraphStyle * @param mixed $paragraphStyle

View File

@ -138,12 +138,14 @@ abstract class AbstractPart
/** /**
* Read w:pPr * Read w:pPr
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode) protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode)
{ {
if (!$xmlReader->elementExists('w:pPr', $domNode)) { if (!$xmlReader->elementExists('w:pPr', $domNode)) {
return; return '';
} }
$style = array(); $style = array();
@ -200,19 +202,21 @@ abstract class AbstractPart
/** /**
* Read w:rPr * Read w:rPr
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode) protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode)
{ {
if (is_null($domNode)) { if (is_null($domNode)) {
return; return null;
} }
// Hyperlink has an extra w:r child // Hyperlink has an extra w:r child
if ($domNode->nodeName == 'w:hyperlink') { if ($domNode->nodeName == 'w:hyperlink') {
$domNode = $xmlReader->getElement('w:r', $domNode); $domNode = $xmlReader->getElement('w:r', $domNode);
} }
if (!$xmlReader->elementExists('w:rPr', $domNode)) { if (!$xmlReader->elementExists('w:rPr', $domNode)) {
return; return null;
} }
$style = array(); $style = array();
@ -272,6 +276,8 @@ abstract class AbstractPart
/** /**
* Read w:tblPr * Read w:tblPr
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return string|array|null * @return string|array|null
* @todo Capture w:tblStylePr w:type="firstRow" * @todo Capture w:tblStylePr w:type="firstRow"
*/ */

View File

@ -121,6 +121,8 @@ class Document extends AbstractPart
/** /**
* Read w:p * Read w:p
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param mixed $parent * @param mixed $parent
* @param string $docPart * @param string $docPart
* *
@ -209,6 +211,8 @@ class Document extends AbstractPart
/** /**
* Read w:tbl * Read w:tbl
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @param mixed $parent * @param mixed $parent
* @param string $docPart * @param string $docPart
*/ */
@ -266,6 +270,8 @@ class Document extends AbstractPart
/** /**
* Read w:sectPr * Read w:sectPr
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode) private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode)
@ -326,6 +332,8 @@ class Document extends AbstractPart
/** /**
* Read w:tcPr * Read w:tcPr
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $domNode
* @return array|null * @return array|null
*/ */
private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode) private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode)

View File

@ -87,6 +87,8 @@ class Numbering extends AbstractPart
/** /**
* Read numbering level definition from w:abstractNum and w:num * Read numbering level definition from w:abstractNum and w:num
* *
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $subnode
* @param integer $levelId * @param integer $levelId
* @return array * @return array
*/ */

View File

@ -52,6 +52,7 @@ class Html
* *
* @param \DOMNode $node Node to check on attributes and to compile a style array * @param \DOMNode $node Node to check on attributes and to compile a style array
* @param array $style is supplied, the inline style attributes are added to the already existing style * @param array $style is supplied, the inline style attributes are added to the already existing style
* @return array
*/ */
protected static function parseInlineStyle($node, $style = array()) protected static function parseInlineStyle($node, $style = array())
{ {
@ -91,6 +92,7 @@ class Html
} }
} }
} }
return $style; return $style;
} }
@ -173,7 +175,7 @@ class Html
// } // }
break; break;
case 'tr': case 'tr':
/** @var \PhpOffice\PhpWord\Element\Table $object Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Table $object Type hint */
$styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']); $styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']);
$newobject = $object->addRow(); $newobject = $object->addRow();
// if ($attributes->getNamedItem('height') !== null) { // if ($attributes->getNamedItem('height') !== null) {
@ -181,7 +183,7 @@ class Html
// } // }
break; break;
case 'td': case 'td':
/** @var \PhpOffice\PhpWord\Element\Row $object Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Row $object Type hint */
$styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']); $styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']);
// if ($attributes->getNamedItem('width') !== null) { // if ($attributes->getNamedItem('width') !== null) {
// $newobject=$object->addCell($width=$attributes->getNamedItem('width')->value); // $newobject=$object->addCell($width=$attributes->getNamedItem('width')->value);

View File

@ -47,6 +47,7 @@ class XMLReader
* @param string $zipFile * @param string $zipFile
* @param string $xmlFile * @param string $xmlFile
* @return \DOMDocument|false * @return \DOMDocument|false
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function getDomFromZip($zipFile, $xmlFile) public function getDomFromZip($zipFile, $xmlFile)
{ {
@ -76,6 +77,7 @@ class XMLReader
* Get elements * Get elements
* *
* @param string $path * @param string $path
* @param \DOMElement $contextNode
* @return \DOMNodeList * @return \DOMNodeList
*/ */
public function getElements($path, \DOMElement $contextNode = null) public function getElements($path, \DOMElement $contextNode = null)
@ -94,6 +96,7 @@ class XMLReader
* Get element * Get element
* *
* @param string $path * @param string $path
* @param \DOMElement $contextNode
* @return \DOMElement|null * @return \DOMElement|null
*/ */
public function getElement($path, \DOMElement $contextNode = null) public function getElement($path, \DOMElement $contextNode = null)
@ -110,6 +113,7 @@ class XMLReader
* Get element attribute * Get element attribute
* *
* @param string $attribute * @param string $attribute
* @param \DOMElement $contextNode
* @param string $path * @param string $path
* @return string|null * @return string|null
*/ */
@ -134,6 +138,7 @@ class XMLReader
* Get element value * Get element value
* *
* @param string $path * @param string $path
* @param \DOMElement $contextNode
* @return string|null * @return string|null
*/ */
public function getValue($path, \DOMElement $contextNode = null) public function getValue($path, \DOMElement $contextNode = null)
@ -150,6 +155,7 @@ class XMLReader
* Count elements * Count elements
* *
* @param string $path * @param string $path
* @param \DOMElement $contextNode
* @return integer * @return integer
*/ */
public function countElements($path, \DOMElement $contextNode = null) public function countElements($path, \DOMElement $contextNode = null)
@ -163,6 +169,7 @@ class XMLReader
* Element exists * Element exists
* *
* @param string $path * @param string $path
* @param \DOMElement $contextNode
* @return boolean * @return boolean
*/ */
public function elementExists($path, \DOMElement $contextNode = null) public function elementExists($path, \DOMElement $contextNode = null)

View File

@ -86,6 +86,7 @@ class ZipArchive
* *
* @param string $filename Directory/Name of the file to add to the zip archive * @param string $filename Directory/Name of the file to add to the zip archive
* @param string $localname Directory/Name of the file added to the zip * @param string $localname Directory/Name of the file added to the zip
* @return bool
*/ */
public function addFile($filename, $localname = null) public function addFile($filename, $localname = null)
{ {
@ -118,6 +119,7 @@ class ZipArchive
* *
* @param string $localname Directory/Name of the file to add to the zip archive * @param string $localname Directory/Name of the file to add to the zip archive
* @param string $contents String of data to add to the zip archive * @param string $contents String of data to add to the zip archive
* @return bool
*/ */
public function addFromString($localname, $contents) public function addFromString($localname, $contents)
{ {

View File

@ -83,13 +83,13 @@ class Style
/** /**
* Add title style * Add title style
* *
* @param int $titleCount * @param int $depth
* @param array $fontStyle * @param array $fontStyle
* @param array $paragraphStyle * @param array $paragraphStyle
*/ */
public static function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null) public static function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
{ {
self::setStyleValues("Heading_{$titleCount}", new Font('title', $paragraphStyle), $fontStyle); self::setStyleValues("Heading_{$depth}", new Font('title', $paragraphStyle), $fontStyle);
} }
/** /**

View File

@ -227,6 +227,8 @@ abstract class AbstractStyle
* @param mixed $value * @param mixed $value
* @param array $enum * @param array $enum
* @param mixed $default * @param mixed $default
* @return mixed
* @throws \InvalidArgumentException
*/ */
protected function setEnumVal($value = null, $enum = array(), $default = null) protected function setEnumVal($value = null, $enum = array(), $default = null)
{ {
@ -245,11 +247,13 @@ abstract class AbstractStyle
* @param mixed $value * @param mixed $value
* @param string $styleName * @param string $styleName
* @param mixed $style * @param mixed $style
* @return mixed
*/ */
protected function setObjectVal($value, $styleName, &$style) protected function setObjectVal($value, $styleName, &$style)
{ {
$styleClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' . $styleName; $styleClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' . $styleName;
if (is_array($value)) { if (is_array($value)) {
/** @var \PhpOffice\PhpWord\Style\AbstractStyle $style Type hint */
if (!$style instanceof $styleClass) { if (!$style instanceof $styleClass) {
$style = new $styleClass(); $style = new $styleClass();
} }
@ -265,6 +269,7 @@ abstract class AbstractStyle
* Set style using associative array * Set style using associative array
* *
* @param array $style * @param array $style
* @return self
* @deprecated 0.11.0 * @deprecated 0.11.0
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */

View File

@ -146,6 +146,8 @@ class Cell extends Border
{ {
if (!is_null($this->shading)) { if (!is_null($this->shading)) {
return $this->shading->getFill(); return $this->shading->getFill();
} else {
return null;
} }
} }

View File

@ -562,6 +562,8 @@ class Font extends AbstractStyle
{ {
if (!is_null($this->shading)) { if (!is_null($this->shading)) {
return $this->shading->getFill(); return $this->shading->getFill();
} else {
return null;
} }
} }

View File

@ -127,6 +127,7 @@ class Paragraph extends AbstractStyle
* *
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @return self
*/ */
public function setStyleValue($key, $value) public function setStyleValue($key, $value)
{ {
@ -172,6 +173,8 @@ class Paragraph extends AbstractStyle
{ {
if (!is_null($this->spacing)) { if (!is_null($this->spacing)) {
return $this->spacing->getBefore(); return $this->spacing->getBefore();
} else {
return null;
} }
} }
@ -195,6 +198,8 @@ class Paragraph extends AbstractStyle
{ {
if (!is_null($this->spacing)) { if (!is_null($this->spacing)) {
return $this->spacing->getAfter(); return $this->spacing->getAfter();
} else {
return null;
} }
} }
@ -218,6 +223,8 @@ class Paragraph extends AbstractStyle
{ {
if (!is_null($this->spacing)) { if (!is_null($this->spacing)) {
return $this->spacing->getLine(); return $this->spacing->getLine();
} else {
return null;
} }
} }
@ -246,7 +253,7 @@ class Paragraph extends AbstractStyle
* Set the line height * Set the line height
* *
* @param int|float|string $lineHeight * @param int|float|string $lineHeight
* @return $this * @return self
* @throws \PhpOffice\PhpWord\Exception\InvalidStyleException * @throws \PhpOffice\PhpWord\Exception\InvalidStyleException
*/ */
public function setLineHeight($lineHeight) public function setLineHeight($lineHeight)
@ -273,6 +280,8 @@ class Paragraph extends AbstractStyle
{ {
if (!is_null($this->indentation)) { if (!is_null($this->indentation)) {
return $this->indentation->getLeft(); return $this->indentation->getLeft();
} else {
return null;
} }
} }
@ -296,6 +305,8 @@ class Paragraph extends AbstractStyle
{ {
if (!is_null($this->indentation)) { if (!is_null($this->indentation)) {
return $this->indentation->getHanging(); return $this->indentation->getHanging();
} else {
return null;
} }
} }

View File

@ -420,7 +420,7 @@ class Section extends Border
* Set page numbering start * Set page numbering start
* *
* @param null|int $pageNumberingStart * @param null|int $pageNumberingStart
* @return $this * @return self
*/ */
public function setPageNumberingStart($pageNumberingStart = null) public function setPageNumberingStart($pageNumberingStart = null)
{ {

View File

@ -149,6 +149,7 @@ abstract class AbstractWriter implements WriterInterface
* @param bool $value * @param bool $value
* @param string $directory * @param string $directory
* @return self * @return self
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function setUseDiskCaching($value = false, $directory = null) public function setUseDiskCaching($value = false, $directory = null)
{ {
@ -257,6 +258,7 @@ abstract class AbstractWriter implements WriterInterface
* *
* @param string $filename * @param string $filename
* @return mixed ZipArchive object * @return mixed ZipArchive object
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
protected function getZipArchive($filename) protected function getZipArchive($filename)
{ {

View File

@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Writer\HTML\Element\Container; use PhpOffice\PhpWord\Writer\HTML\Element\Container;
use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter; use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter;
use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter;

View File

@ -51,6 +51,8 @@ abstract class AbstractElement
/** /**
* Create new instance * Create new instance
* *
* @param \PhpOffice\PhpWord\Writer\AbstractWriter $parentWriter
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP * @param bool $withoutP
*/ */
public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false) public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false)

View File

@ -40,7 +40,7 @@ class Container extends AbstractElement
{ {
$container = $this->element; $container = $this->element;
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
return; return '';
} }
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
$withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote')) ? true : false; $withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote')) ? true : false;

View File

@ -39,9 +39,9 @@ class Footnote extends AbstractElement
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) {
return; return '';
} }
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
$parentWriter = $this->parentWriter; $parentWriter = $this->parentWriter;
$noteId = count($parentWriter->getNotes()) + 1; $noteId = count($parentWriter->getNotes()) + 1;

View File

@ -35,9 +35,9 @@ class Image extends Text
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) {
return; return '';
} }
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
$parentWriter = $this->parentWriter; $parentWriter = $this->parentWriter;
$content = ''; $content = '';
@ -59,6 +59,7 @@ class Image extends Text
/** /**
* Get Base64 image data * Get Base64 image data
* *
* @param \PhpOffice\PhpWord\Element\Image $element
* @return string|null * @return string|null
*/ */
private function getBase64ImageData(ImageElement $element) private function getBase64ImageData(ImageElement $element)

View File

@ -32,7 +32,7 @@ class Link extends Text
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) {
return; return '';
} }
$content = ''; $content = '';

View File

@ -32,7 +32,7 @@ class ListItem extends AbstractElement
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) {
return; return '';
} }
$text = htmlspecialchars($this->element->getTextObject()->getText()); $text = htmlspecialchars($this->element->getTextObject()->getText());

View File

@ -32,7 +32,7 @@ class Table extends AbstractElement
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) {
return; return '';
} }
$content = ''; $content = '';

View File

@ -53,7 +53,7 @@ class Text extends AbstractElement
/** /**
* Closing tag * Closing tag
* *
* @var strings * @var string
*/ */
private $closingTags = ''; private $closingTags = '';
@ -64,7 +64,7 @@ class Text extends AbstractElement
*/ */
public function write() public function write()
{ {
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element; $element = $this->element;
$this->getFontStyle(); $this->getFontStyle();
@ -142,7 +142,7 @@ class Text extends AbstractElement
*/ */
private function getParagraphStyle() private function getParagraphStyle()
{ {
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element; $element = $this->element;
$style = ''; $style = '';
if (method_exists($element, 'getParagraphStyle')) { if (method_exists($element, 'getParagraphStyle')) {
@ -168,7 +168,7 @@ class Text extends AbstractElement
*/ */
private function getFontStyle() private function getFontStyle()
{ {
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element; $element = $this->element;
$style = ''; $style = '';
$fontStyle = $element->getFontStyle(); $fontStyle = $element->getFontStyle();

View File

@ -32,7 +32,7 @@ class Title extends AbstractElement
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) {
return; return '';
} }
$tag = 'h' . $this->element->getDepth(); $tag = 'h' . $this->element->getDepth();

View File

@ -56,7 +56,7 @@ abstract class AbstractStyle
public function getStyle() public function getStyle()
{ {
if (!$this->style instanceof Style && !is_array($this->style)) { if (!$this->style instanceof Style && !is_array($this->style)) {
return; return '';
} }
return $this->style; return $this->style;

View File

@ -36,7 +36,7 @@ class Font extends AbstractStyle
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
return; return '';
} }
$css = array(); $css = array();

View File

@ -33,7 +33,7 @@ class Image extends AbstractStyle
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
return; return '';
} }
$css = array(); $css = array();

View File

@ -35,7 +35,7 @@ class Paragraph extends AbstractStyle
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
return; return '';
} }
$css = array(); $css = array();

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\ODText\Element; namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\PhpWord\Exception\Exception;
/** /**
* Text element writer * Text element writer
* *

View File

@ -19,8 +19,8 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
/** /**
* ODText writer part abstract * ODText writer part abstract

View File

@ -23,8 +23,8 @@ use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Writer\ODText\Element\Container; use PhpOffice\PhpWord\Writer\ODText\Element\Container;
/** /**

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\ODText\Part; namespace PhpOffice\PhpWord\Writer\ODText\Part;
use PhpOffice\PhpWord\PhpWord;
/** /**
* ODText meta part writer: meta.xml * ODText meta part writer: meta.xml
*/ */

View File

@ -37,6 +37,7 @@ class PDF
* Instantiate a new renderer of the configured type within this container class * Instantiate a new renderer of the configured type within this container class
* *
* @param \PhpOffice\PhpWord\PhpWord $phpWord * @param \PhpOffice\PhpWord\PhpWord $phpWord
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function __construct(PhpWord $phpWord) public function __construct(PhpWord $phpWord)
{ {
@ -62,6 +63,7 @@ class PDF
* @param string $name Renderer library method name * @param string $name Renderer library method name
* @param mixed[] $arguments Array of arguments to pass to the renderer method * @param mixed[] $arguments Array of arguments to pass to the renderer method
* @return mixed Returned data from the PDF renderer wrapper method * @return mixed Returned data from the PDF renderer wrapper method
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {

View File

@ -90,10 +90,12 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
* 'arialunicid0-japanese' * 'arialunicid0-japanese'
* *
* @param string $fontName * @param string $fontName
* @return self
*/ */
public function setFont($fontName) public function setFont($fontName)
{ {
$this->font = $fontName; $this->font = $fontName;
return $this; return $this;
} }
@ -146,6 +148,7 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
* *
* @param string $pFilename Name of the file to save as * @param string $pFilename Name of the file to save as
* @return resource * @return resource
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
protected function prepareForSave($pFilename = null) protected function prepareForSave($pFilename = null)
{ {

View File

@ -30,6 +30,7 @@ class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\Write
* Create new instance * Create new instance
* *
* @param PhpWord $phpWord PhpWord object * @param PhpWord $phpWord PhpWord object
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function __construct(PhpWord $phpWord) public function __construct(PhpWord $phpWord)
{ {

View File

@ -145,7 +145,7 @@ class RTF extends AbstractWriter implements WriterInterface
// Set the color tbl group // Set the color tbl group
$content .= '{\colortbl '; $content .= '{\colortbl ';
foreach ($this->colorTable as $idx => $color) { foreach ($this->colorTable as $color) {
$arrColor = Drawing::htmlToRGB($color); $arrColor = Drawing::htmlToRGB($color);
$content .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . ''; $content .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . '';
} }

View File

@ -18,8 +18,8 @@
namespace PhpOffice\PhpWord\Writer\RTF\Element; namespace PhpOffice\PhpWord\Writer\RTF\Element;
use PhpOffice\PhpWord\Shared\String; use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter;
@ -34,14 +34,14 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle
/** /**
* Font style * Font style
* *
* @var \PhpWord\PhpOffice\Style\Font * @var \PhpOffice\PhpWord\Style\Font
*/ */
private $fontStyle; private $fontStyle;
/** /**
* Paragraph style * Paragraph style
* *
* @var \PhpWord\PhpOffice\Style\Paragraph * @var \PhpOffice\PhpWord\Style\Paragraph
*/ */
private $paragraphStyle; private $paragraphStyle;
@ -50,10 +50,10 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle
*/ */
protected function getStyles() protected function getStyles()
{ {
/** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */
$parentWriter = $this->parentWriter; $parentWriter = $this->parentWriter;
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element; $element = $this->element;
// Font style // Font style
@ -93,7 +93,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle
protected function writeOpening() protected function writeOpening()
{ {
if ($this->withoutP || !$this->paragraphStyle instanceof ParagraphStyle) { if ($this->withoutP || !$this->paragraphStyle instanceof ParagraphStyle) {
return; return '';
} }
$styleWriter = new ParagraphStyleWriter($this->paragraphStyle); $styleWriter = new ParagraphStyleWriter($this->paragraphStyle);
@ -119,7 +119,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle
protected function writeClosing() protected function writeClosing()
{ {
if ($this->withoutP) { if ($this->withoutP) {
return; return '';
} }
return '\par' . PHP_EOL; return '\par' . PHP_EOL;
@ -136,7 +136,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle
return ''; return '';
} }
/** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */
$parentWriter = $this->parentWriter; $parentWriter = $this->parentWriter;
// Create style writer and set color/name index // Create style writer and set color/name index

View File

@ -32,7 +32,7 @@ class Link extends AbstractElement
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) {
return; return '';
} }
$this->getStyles(); $this->getStyles();

View File

@ -31,11 +31,11 @@ class Text extends AbstractElement
*/ */
public function write() public function write()
{ {
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element; $element = $this->element;
$elementClass = str_replace('\\Writer\\RTF', '', get_class($this)); $elementClass = str_replace('\\Writer\\RTF', '', get_class($this));
if (!$element instanceof $elementClass) { if (!$element instanceof $elementClass) {
return; return '';
} }
$this->getStyles(); $this->getStyles();

View File

@ -31,7 +31,7 @@ class TextBreak extends AbstractElement
*/ */
public function write() public function write()
{ {
/** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */
$parentWriter = $this->parentWriter; $parentWriter = $this->parentWriter;
$parentWriter->setLastParagraphStyle(); $parentWriter->setLastParagraphStyle();

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\RTF\Element; namespace PhpOffice\PhpWord\Writer\RTF\Element;
use PhpOffice\PhpWord\Writer\RTF\Element\Container;
/** /**
* TextRun element RTF writer * TextRun element RTF writer
* *

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\RTF\Style; namespace PhpOffice\PhpWord\Writer\RTF\Style;
use PhpOffice\PhpWord\Style\AbstractStyle as Style;
/** /**
* Abstract RTF style writer * Abstract RTF style writer
* *

View File

@ -17,7 +17,6 @@
namespace PhpOffice\PhpWord\Writer\RTF\Style; namespace PhpOffice\PhpWord\Writer\RTF\Style;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
/** /**
@ -46,7 +45,7 @@ class Font extends AbstractStyle
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
return; return '';
} }
$content = ''; $content = '';

View File

@ -35,7 +35,7 @@ class Paragraph extends AbstractStyle
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) {
return; return '';
} }
$alignments = array( $alignments = array(

View File

@ -88,6 +88,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
* Save document by name * Save document by name
* *
* @param string $filename * @param string $filename
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function save($filename = null) public function save($filename = null)
{ {
@ -191,6 +192,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
/** /**
* Add header/footer content * Add header/footer content
* *
* @param \PhpOffice\PhpWord\Element\Section $section
* @param mixed $objZip * @param mixed $objZip
* @param string $elmType header|footer * @param string $elmType header|footer
* @param integer $rId * @param integer $rId

View File

@ -58,6 +58,8 @@ abstract class AbstractElement
/** /**
* Create new instance * Create new instance
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\AbstractElement $element
* @param bool $withoutP * @param bool $withoutP
*/ */
public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false) public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false)
@ -81,14 +83,11 @@ abstract class AbstractElement
* Get element * Get element
* *
* @return \PhpOffice\PhpWord\Element\AbstractElement * @return \PhpOffice\PhpWord\Element\AbstractElement
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
protected function getElement() protected function getElement()
{ {
if (!is_null($this->element)) {
return $this->element; return $this->element;
} else {
throw new Exception('No element assigned.');
}
} }
/** /**

View File

@ -64,6 +64,8 @@ class TOC extends AbstractElement
/** /**
* Write title * Write title
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\TOC $element
* @param \PhpOffice\PhpWord\Element\Title $title * @param \PhpOffice\PhpWord\Element\Title $title
* @param bool $writeFieldMark * @param bool $writeFieldMark
*/ */
@ -130,6 +132,8 @@ class TOC extends AbstractElement
/** /**
* Write style * Write style
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\TOC $element
* @param int $indent * @param int $indent
*/ */
private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent) private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent)
@ -141,8 +145,8 @@ class TOC extends AbstractElement
$xmlWriter->startElement('w:pPr'); $xmlWriter->startElement('w:pPr');
// Paragraph // Paragraph
if ($isObject && !is_null($fontStyle->getParagraphStyle())) { if ($isObject && !is_null($fontStyle->getParagraph())) {
$styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraphStyle()); $styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraph());
$styleWriter->write(); $styleWriter->write();
} }

View File

@ -89,7 +89,7 @@ class Text extends AbstractElement
{ {
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->getElement(); $element = $this->getElement();
$paragraphStyle = $element->getParagraphStyle(); $paragraphStyle = $element->getParagraphStyle();
$styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle); $styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle);
@ -104,7 +104,7 @@ class Text extends AbstractElement
{ {
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
/** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->getElement(); $element = $this->getElement();
$fontStyle = $element->getFontStyle(); $fontStyle = $element->getFontStyle();
$styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle);

View File

@ -32,7 +32,7 @@ class ContentTypes extends AbstractPart
*/ */
public function write() public function write()
{ {
/** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */
$parentWriter = $this->getParentWriter(); $parentWriter = $this->getParentWriter();
$contentTypes = $parentWriter->getContentTypes(); $contentTypes = $parentWriter->getContentTypes();
@ -82,16 +82,12 @@ class ContentTypes extends AbstractPart
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault) private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{ {
foreach ($parts as $partName => $contentType) { foreach ($parts as $partName => $contentType) {
if ($partName != '' && $contentType != '') {
$partType = $isDefault ? 'Default' : 'Override'; $partType = $isDefault ? 'Default' : 'Override';
$partAttribute = $isDefault ? 'Extension' : 'PartName'; $partAttribute = $isDefault ? 'Extension' : 'PartName';
$xmlWriter->startElement($partType); $xmlWriter->startElement($partType);
$xmlWriter->writeAttribute($partAttribute, $partName); $xmlWriter->writeAttribute($partAttribute, $partName);
$xmlWriter->writeAttribute('ContentType', $contentType); $xmlWriter->writeAttribute('ContentType', $contentType);
$xmlWriter->endElement(); $xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
} }
} }
} }

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Word2007 extended document properties part writer: docProps/app.xml * Word2007 extended document properties part writer: docProps/app.xml
* *

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Word2007 core document properties part writer: docProps/core.xml * Word2007 core document properties part writer: docProps/core.xml
* *

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Element\Section; use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Element\Container;
use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter;

View File

@ -106,7 +106,7 @@ class Footnotes extends AbstractPart
$xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // w:p
$xmlWriter->endElement(); // $this->elementNode $xmlWriter->endElement(); // $this->elementNode
/** @var array $elements Scrutinizer type hint */ /** @var array $elements Type hint */
$elements = $this->elements; $elements = $this->elements;
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element instanceof Footnote) { if ($element instanceof Footnote) {

View File

@ -18,9 +18,9 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle;
use PhpOffice\PhpWord\Style\NumberingLevel; use PhpOffice\PhpWord\Style\NumberingLevel;
use PhpOffice\PhpWord\Style;
/** /**
* Word2007 numbering part writer: word/numbering.xml * Word2007 numbering part writer: word/numbering.xml

View File

@ -97,6 +97,7 @@ class Rels extends AbstractPart
* @param string $type Relationship type * @param string $type Relationship type
* @param string $target Relationship target * @param string $target Relationship target
* @param string $targetMode Relationship target mode * @param string $targetMode Relationship target mode
* @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '') private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '')
{ {

View File

@ -41,7 +41,7 @@ class RelsDocument extends Rels
); );
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
/** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */
$parentWriter = $this->getParentWriter(); $parentWriter = $this->getParentWriter();
$this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships()); $this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships());

View File

@ -127,7 +127,7 @@ class Settings extends AbstractPart
} else { } else {
$xmlWriter->startElement($settingKey); $xmlWriter->startElement($settingKey);
/** @var array $settingValue Scrutinizer type hint */ /** @var array $settingValue Type hint */
foreach ($settingValue as $childKey => $childValue) { foreach ($settingValue as $childKey => $childValue) {
if ($childKey == '@attributes') { if ($childKey == '@attributes') {
foreach ($childValue as $key => $val) { foreach ($childValue as $key => $val) {

View File

@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Table; use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
@ -155,6 +155,7 @@ class Styles extends AbstractPart
* Write default font and other default styles * Write default font and other default styles
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param array $styles * @param array $styles
*/ */
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles) private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)

View File

@ -49,6 +49,7 @@ abstract class AbstractStyle
/** /**
* Create new instance * Create new instance
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style * @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style
*/ */
public function __construct(XMLWriter $xmlWriter, $style = null) public function __construct(XMLWriter $xmlWriter, $style = null)

View File

@ -136,6 +136,7 @@ class Image extends AbstractStyle
/** /**
* Get element style * Get element style
* *
* @param \PhpOffice\PhpWord\Style\Image $style
* @return array * @return array
*/ */
private function getElementStyle(ImageStyle $style) private function getElementStyle(ImageStyle $style)

View File

@ -71,6 +71,7 @@ class MarginBorder extends AbstractStyle
/** /**
* Write side * Write side
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $side * @param string $side
* @param int $width * @param int $width
* @param string $color * @param string $color

View File

@ -85,6 +85,7 @@ class Table extends AbstractStyle
/** /**
* Write width * Write width
* *
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param int $width * @param int $width
* @param string $unit * @param string $unit
*/ */

View File

@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase
*/ */
public function testUnmatchedElements() public function testUnmatchedElements()
{ {
$styles = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title'); $elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title');
foreach ($styles as $style) { foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $style; $objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element;
$parentWriter = new HTML(); $parentWriter = new HTML();
$element = new \PhpOffice\PhpWord\Element\PageBreak(); $newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($parentWriter, $element); $object = new $objectClass($parentWriter, $newElement);
$this->assertEquals('', $object->write()); $this->assertEquals('', $object->write());
} }

View File

@ -64,6 +64,7 @@ class HTMLTest extends \PHPUnit_Framework_TestCase
$docProps = $phpWord->getDocumentProperties(); $docProps = $phpWord->getDocumentProperties();
$docProps->setTitle('HTML Test'); $docProps->setTitle('HTML Test');
$phpWord->addTitleStyle(1, array('bold' => true));
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11,
'color' => 'FF0000', 'fgColor' => 'FF0000')); 'color' => 'FF0000', 'fgColor' => 'FF0000'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));

View File

@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase
*/ */
public function testUnmatchedElements() public function testUnmatchedElements()
{ {
$styles = array('Image', 'Link', 'Table', 'Text'); $elements = array('Image', 'Link', 'Table', 'Text');
foreach ($styles as $style) { foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $style; $objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element;
$xmlWriter = new XMLWriter(); $xmlWriter = new XMLWriter();
$element = new \PhpOffice\PhpWord\Element\PageBreak(); $newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($xmlWriter, $element); $object = new $objectClass($xmlWriter, $newElement);
$object->write(); $object->write();
$this->assertEquals('', $xmlWriter->getData()); $this->assertEquals('', $xmlWriter->getData());

View File

@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase
*/ */
public function testUnmatchedElements() public function testUnmatchedElements()
{ {
$styles = array('Container', 'Text', 'Title', 'Link'); $elements = array('Container', 'Text', 'Title', 'Link');
foreach ($styles as $style) { foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $style; $objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $element;
$parentWriter = new RTF(); $parentWriter = new RTF();
$element = new \PhpOffice\PhpWord\Element\PageBreak(); $newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($parentWriter, $element); $object = new $objectClass($parentWriter, $newElement);
$this->assertEquals('', $object->write()); $this->assertEquals('', $object->write());
} }

View File

@ -59,7 +59,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11,
'color' => 'FF0000', 'fgColor' => 'FF0000')); 'color' => 'FF0000', 'fgColor' => '00FF00'));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph'); $section->addText('Test 1', 'Font', 'Paragraph');

View File

@ -28,15 +28,15 @@ class ElementTest extends \PHPUnit_Framework_TestCase
*/ */
public function testUnmatchedElements() public function testUnmatchedElements()
{ {
$styles = array( $elements = array(
'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun',
'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC' 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC'
); );
foreach ($styles as $style) { foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $style; $objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $element;
$xmlWriter = new XMLWriter(); $xmlWriter = new XMLWriter();
$element = new \PhpOffice\PhpWord\Element\PageBreak(); $newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($xmlWriter, $element); $object = new $objectClass($xmlWriter, $newElement);
$object->write(); $object->write();
$this->assertEquals('', $xmlWriter->getData()); $this->assertEquals('', $xmlWriter->getData());

View File

@ -72,6 +72,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$section->addListItem('List Item 1', 0); $section->addListItem('List Item 1', 0);
$section->addListItem('List Item 2', 0); $section->addListItem('List Item 2', 0);
$section->addListItem('List Item 3', 0); $section->addListItem('List Item 3', 0);
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addTitle('Title 2', 2); $section->addTitle('Title 2', 2);
$section->addObject($objectSrc); $section->addObject($objectSrc);
@ -80,6 +81,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin', 'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin',
'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0')); 'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0'));
$section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center')); $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center'));
$section->addListItemRun()->addText('List item run 1');
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
@ -113,22 +115,27 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{ {
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
$tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090));
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'center')); // Style #1 $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'tabs' => $tabs)); // Style #1
$phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true)); // Style #2 $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true)); // Style #2
$phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3 $phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3
$phpWord->addTableStyle('tStyle', array('borderSize' => 1));
$fontStyle = new Font('text', array('align' => 'center')); $fontStyle = new Font('text', array('align' => 'center'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #4 $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5
$section->addObject($objectSrc, array('align' => 'center')); $section->addObject($objectSrc, array('align' => 'center'));
$section->addTOC($fontStyle); $section->addTOC($fontStyle);
$section->addTitle('Title 1', 1); $section->addTitle('Title 1', 1);
$section->addTOC('fStyle'); $section->addTOC('fStyle');
$table = $section->addTable('tStyle');
$table->setWidth(100);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
// List item // List item
$element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId'); $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId');
$this->assertEquals(4, $element->getAttribute('w:val')); $this->assertEquals(5, $element->getAttribute('w:val'));
// Object // Object
$element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject'); $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject');
@ -497,6 +504,10 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$table->addCell(40); $table->addCell(40);
$table->addCell(40); $table->addCell(40);
$table->addRow();
$cell = $table->addCell(200, array('borderRightColor' => 'FF0000'));
$cell->getStyle()->setGridSpan(5);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan'); $element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan');

View File

@ -0,0 +1,41 @@
<?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\Tests\Writer\Word2007\Part;
use PhpOffice\PhpWord\Writer\Word2007\Part\RelsPart;
/**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part subnamespace
*
* Covers miscellaneous tests
*/
class PartTest extends \PHPUnit_Framework_TestCase
{
/**
* Test exception when no type or target assigned to a relation
*
* @covers \PhpOffice\PhpWord\Writer\Word2007\Part\Rels::writeRel
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage Invalid parameters passed.
*/
public function testRelsWriteRelException()
{
$object = new RelsPart();
$object->setMedia(array(array('foo' => 'bar')));
$object->write();
}
}