diff --git a/Classes/PHPWord.php b/Classes/PHPWord.php index d591b94e..e7501d85 100755 --- a/Classes/PHPWord.php +++ b/Classes/PHPWord.php @@ -188,8 +188,8 @@ class PHPWord /** * Adds a paragraph style definition to styles.xml * - * @param $styleName string - * @param $styles array + * @param string $styleName + * @param array $styles */ public function addParagraphStyle($styleName, $styles) { @@ -199,8 +199,9 @@ class PHPWord /** * Adds a font style definition to styles.xml * - * @param $styleName string - * @param $styles array + * @param string $styleName + * @param array $styleFont + * @param array $styleParagraph */ public function addFontStyle($styleName, $styleFont, $styleParagraph = null) { @@ -210,8 +211,9 @@ class PHPWord /** * Adds a table style definition to styles.xml * - * @param $styleName string - * @param $styles array + * @param string $styleName + * @param array $styleTable + * @param array $styleFirstRow */ public function addTableStyle($styleName, $styleTable, $styleFirstRow = null) { @@ -221,8 +223,9 @@ class PHPWord /** * Adds a heading style definition to styles.xml * - * @param $titleCount int - * @param $styles array + * @param int $titleCount + * @param array $styleFont + * @param array $styleParagraph */ public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) { @@ -232,8 +235,8 @@ class PHPWord /** * Adds a hyperlink style to styles.xml * - * @param $styleName string - * @param $styles array + * @param string $styleName + * @param array $styles */ public function addLinkStyle($styleName, $styles) { diff --git a/Classes/PHPWord/Autoloader.php b/Classes/PHPWord/Autoloader.php index aa36efc8..6a915563 100755 --- a/Classes/PHPWord/Autoloader.php +++ b/Classes/PHPWord/Autoloader.php @@ -69,7 +69,7 @@ class PHPWord_Autoloader /** * Autoloader * - * @param string + * @param string $class */ public static function autoload($class) { diff --git a/Classes/PHPWord/Exceptions/Exception.php b/Classes/PHPWord/Exceptions/Exception.php index 11cb0516..d00ed0a9 100755 --- a/Classes/PHPWord/Exceptions/Exception.php +++ b/Classes/PHPWord/Exceptions/Exception.php @@ -1,4 +1,29 @@ getImageExtension(); $media['isMemImage'] = true; $media['createfunction'] = $memoryImage->getImageCreateFunction(); $media['imagefunction'] = $memoryImage->getImageFunction(); } else { - $imageType = exif_imagetype($src); - if ($imageType === IMAGETYPE_JPEG) { - $extension = 'jpg'; - } elseif ($imageType === IMAGETYPE_GIF) { - $extension = 'gif'; - } elseif ($imageType === IMAGETYPE_PNG) { - $extension = 'png'; - } elseif ($imageType === IMAGETYPE_BMP) { - $extension = 'bmp'; - } elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) { - $extension = 'tif'; - } + $extension = PHPWord_Shared_File::imagetype($src); } $folder = 'media'; diff --git a/Classes/PHPWord/Reader/Abstract.php b/Classes/PHPWord/Reader/Abstract.php index ba7f6565..63b794f8 100644 --- a/Classes/PHPWord/Reader/Abstract.php +++ b/Classes/PHPWord/Reader/Abstract.php @@ -42,6 +42,8 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader protected $readDataOnly = true; /** + * File pointer + * * @var bool|resource */ protected $fileHandle = true; diff --git a/Classes/PHPWord/Section/Footer.php b/Classes/PHPWord/Section/Footer.php index 238bae1b..ba9cb68c 100755 --- a/Classes/PHPWord/Section/Footer.php +++ b/Classes/PHPWord/Section/Footer.php @@ -54,6 +54,8 @@ class PHPWord_Section_Footer /** * Create a new Footer + * + * @param int $sectionCount */ public function __construct($sectionCount) { @@ -95,6 +97,7 @@ class PHPWord_Section_Footer /** * Create a new TextRun * + * @param null|string|array|PHPWord_Style_Paragraph $styleParagraph * @return PHPWord_Section_TextRun */ public function createTextRun($styleParagraph = null) diff --git a/Classes/PHPWord/Section/Footer/PreserveText.php b/Classes/PHPWord/Section/Footer/PreserveText.php index 72443743..d0305fbc 100755 --- a/Classes/PHPWord/Section/Footer/PreserveText.php +++ b/Classes/PHPWord/Section/Footer/PreserveText.php @@ -56,8 +56,10 @@ class PHPWord_Section_Footer_PreserveText /** * Create a new Preserve Text Element * - * @var string $text - * @var mixed $style + * @param string $text + * @param mixed $styleFont + * @param mixed $styleParagraph + * @return PHPWord_Section_Footer_PreserveText */ public function __construct($text = null, $styleFont = null, $styleParagraph = null) { diff --git a/Classes/PHPWord/Section/Footnote.php b/Classes/PHPWord/Section/Footnote.php index 652a3873..7e77aca4 100644 --- a/Classes/PHPWord/Section/Footnote.php +++ b/Classes/PHPWord/Section/Footnote.php @@ -54,6 +54,8 @@ class PHPWord_Section_Footnote /** * Create a new Footnote Element + * + * @param mixed $styleParagraph */ public function __construct($styleParagraph = null) { @@ -78,8 +80,8 @@ class PHPWord_Section_Footnote /** * Add a Text Element * - * @var string $text - * @var mixed $styleFont + * @param null|string $text + * @param mixed $styleFont * @return PHPWord_Section_Text */ public function addText($text = null, $styleFont = null) diff --git a/Classes/PHPWord/Section/Header.php b/Classes/PHPWord/Section/Header.php index 5e1c6bfe..89672e6e 100755 --- a/Classes/PHPWord/Section/Header.php +++ b/Classes/PHPWord/Section/Header.php @@ -83,6 +83,8 @@ class PHPWord_Section_Header /** * Create a new Header + * + * @param int $sectionCount */ public function __construct($sectionCount) { @@ -124,6 +126,7 @@ class PHPWord_Section_Header /** * Create a new TextRun * + * @param mixed $styleParagraph * @return PHPWord_Section_TextRun */ public function createTextRun($styleParagraph = null) diff --git a/Classes/PHPWord/Section/Image.php b/Classes/PHPWord/Section/Image.php index fcaa1cc9..30a10449 100755 --- a/Classes/PHPWord/Section/Image.php +++ b/Classes/PHPWord/Section/Image.php @@ -61,7 +61,6 @@ class PHPWord_Section_Image */ private $_isWatermark; - /** * Create a new Image * @@ -72,13 +71,11 @@ class PHPWord_Section_Image */ public function __construct($src, $style = null, $isWatermark = false) { - $supportedImageTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM); - if (!file_exists($src)) { throw new InvalidImageException; } - if (!in_array(exif_imagetype($src), $supportedImageTypes)) { + if (!PHPWord_Shared_File::imagetype($src)) { throw new UnsupportedImageTypeException; } diff --git a/Classes/PHPWord/Section/Link.php b/Classes/PHPWord/Section/Link.php index 620b08a1..26659b6f 100755 --- a/Classes/PHPWord/Section/Link.php +++ b/Classes/PHPWord/Section/Link.php @@ -70,10 +70,10 @@ class PHPWord_Section_Link /** * Create a new Link Element * - * @var string $linkSrc - * @var string $linkName - * @var mixed $styleFont - * @var mixed $styleParagraph + * @param string $linkSrc + * @param string $linkName + * @param mixed $styleFont + * @param mixed $styleParagraph */ public function __construct($linkSrc, $linkName = null, $styleFont = null, $styleParagraph = null) { diff --git a/Classes/PHPWord/Section/ListItem.php b/Classes/PHPWord/Section/ListItem.php index 83384a94..7d37f3d8 100755 --- a/Classes/PHPWord/Section/ListItem.php +++ b/Classes/PHPWord/Section/ListItem.php @@ -58,8 +58,9 @@ class PHPWord_Section_ListItem * * @param string $text * @param int $depth - * @param mixed $styleText + * @param mixed $styleFont * @param mixed $styleList + * @param mixed $styleParagraph */ public function __construct($text, $depth = 0, $styleFont = null, $styleList = null, $styleParagraph = null) { diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index 1ff3bf64..ba278410 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -158,11 +158,15 @@ class PHPWord_Section_Settings private $pageNumberingStart; /** + * Header height + * * @var int */ private $headerHeight; /** + * Footer height + * * @var int */ private $footerHeight; @@ -594,6 +598,8 @@ class PHPWord_Section_Settings } /** + * Set page numbering start + * * @param null|int $pageNumberingStart * @return $this */ @@ -604,6 +610,8 @@ class PHPWord_Section_Settings } /** + * Get page numbering start + * * @return null|int */ public function getPageNumberingStart() diff --git a/Classes/PHPWord/Section/Table.php b/Classes/PHPWord/Section/Table.php index f5a8a799..80126cba 100755 --- a/Classes/PHPWord/Section/Table.php +++ b/Classes/PHPWord/Section/Table.php @@ -99,6 +99,7 @@ class PHPWord_Section_Table * Add a row * * @param int $height + * @param mixed $style */ public function addRow($height = null, $style = null) { @@ -144,7 +145,7 @@ class PHPWord_Section_Table /** * Set table width * - * @var int $width + * @param int $width */ public function setWidth($width) { diff --git a/Classes/PHPWord/Section/Table/Cell.php b/Classes/PHPWord/Section/Table/Cell.php index f8d6d340..4b620217 100755 --- a/Classes/PHPWord/Section/Table/Cell.php +++ b/Classes/PHPWord/Section/Table/Cell.php @@ -100,7 +100,8 @@ class PHPWord_Section_Table_Cell * Add a Text Element * * @param string $text - * @param mixed $style + * @param mixed $styleFont + * @param mixed $styleParagraph * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) @@ -299,6 +300,7 @@ class PHPWord_Section_Table_Cell /** * Create a new TextRun * + * @param mixed $styleParagraph * @return PHPWord_Section_TextRun */ public function createTextRun($styleParagraph = null) diff --git a/Classes/PHPWord/Section/Text.php b/Classes/PHPWord/Section/Text.php index 8631b66e..d9062520 100755 --- a/Classes/PHPWord/Section/Text.php +++ b/Classes/PHPWord/Section/Text.php @@ -131,6 +131,8 @@ class PHPWord_Section_Text } /** + * Set text content + * * @param string $text * @return $this */ diff --git a/Classes/PHPWord/Section/TextBreak.php b/Classes/PHPWord/Section/TextBreak.php index 85f53edc..859eb621 100755 --- a/Classes/PHPWord/Section/TextBreak.php +++ b/Classes/PHPWord/Section/TextBreak.php @@ -46,6 +46,9 @@ class PHPWord_Section_TextBreak /** * Create a new TextBreak Element + * + * @param mixed $fontStyle + * @param mixed $paragraphStyle */ public function __construct($fontStyle = null, $paragraphStyle = null) { @@ -60,8 +63,8 @@ class PHPWord_Section_TextBreak /** * Set Text style * - * @param null|array|\PHPWord_Style_Font $style - * @param null|array|\PHPWord_Style_Paragraph $paragraphStyle + * @param mixed $style + * @param mixed $paragraphStyle * @return PHPWord_Style_Font */ public function setFontStyle($style = null, $paragraphStyle = null) diff --git a/Classes/PHPWord/Section/TextRun.php b/Classes/PHPWord/Section/TextRun.php index fcb2bd48..890ea45b 100755 --- a/Classes/PHPWord/Section/TextRun.php +++ b/Classes/PHPWord/Section/TextRun.php @@ -48,6 +48,8 @@ class PHPWord_Section_TextRun /** * Create a new TextRun Element + * + * @param mixed $styleParagraph */ public function __construct($styleParagraph = null) { @@ -72,8 +74,8 @@ class PHPWord_Section_TextRun /** * Add a Text Element * - * @var string $text - * @var mixed $styleFont + * @param string $text + * @param mixed $styleFont * @return PHPWord_Section_Text */ public function addText($text = null, $styleFont = null) @@ -113,7 +115,7 @@ class PHPWord_Section_TextRun * Add a Image Element * * @param string $imageSrc - * @param mixed $styleFont + * @param mixed $style * @return PHPWord_Section_Image */ public function addImage($imageSrc, $style = null) @@ -134,9 +136,9 @@ class PHPWord_Section_TextRun /** * Add TextBreak * - * @param int $count - * @param null|string|array|PHPWord_Style_Font $fontStyle - * @param null|string|array|PHPWord_Style_Paragraph $paragraphStyle + * @param int $count + * @param mixed $fontStyle + * @param mixed $paragraphStyle */ public function addTextBreak($count = 1, $fontStyle = null, $paragraphStyle = null) { @@ -148,7 +150,7 @@ class PHPWord_Section_TextRun /** * Create a new Footnote Element * - * @param string $text + * @param mixed $styleParagraph * @return PHPWord_Section_Footnote */ public function createFootnote($styleParagraph = null) diff --git a/Classes/PHPWord/Section/Title.php b/Classes/PHPWord/Section/Title.php index 067370f2..2cc71e11 100755 --- a/Classes/PHPWord/Section/Title.php +++ b/Classes/PHPWord/Section/Title.php @@ -70,8 +70,9 @@ class PHPWord_Section_Title /** * Create a new Title Element * - * @var string $text - * @var int $depth + * @param string $text + * @param int $depth + * @param mixed $style */ public function __construct($text, $depth = 1, $style = null) { @@ -88,7 +89,7 @@ class PHPWord_Section_Title /** * Set Anchor * - * @var int $anchor + * @param int $anchor */ public function setAnchor($anchor) { @@ -108,7 +109,7 @@ class PHPWord_Section_Title /** * Set Bookmark ID * - * @var int $bookmarkId + * @param int $bookmarkId */ public function setBookmarkId($bookmarkId) { diff --git a/Classes/PHPWord/Shared/File.php b/Classes/PHPWord/Shared/File.php index 26a206ba..4ed0e725 100755 --- a/Classes/PHPWord/Shared/File.php +++ b/Classes/PHPWord/Shared/File.php @@ -30,15 +30,20 @@ */ class PHPWord_Shared_File { + const IMAGETYPE_JPEG = 'jpg'; + const IMAGETYPE_GIF = 'gif'; + const IMAGETYPE_PNG = 'png'; + const IMAGETYPE_BMP = 'bmp'; + const IMAGETYPE_TIFF = 'tif'; + /** * Verify if a file exists * - * @param string $pFilename Filename + * @param string $pFilename Filename * @return bool */ public static function file_exists($pFilename) { - // Regular file_exists return file_exists($pFilename); } @@ -50,18 +55,13 @@ class PHPWord_Shared_File */ public static function realpath($pFilename) { - // Returnvalue - $returnValue = ''; - - // Try using realpath() $returnValue = realpath($pFilename); - // Found something? - if ($returnValue == '' || is_null($returnValue)) { + if (!$returnValue) { $pathArray = explode('/', $pFilename); - while (in_array('..', $pathArray) && $pathArray[0] != '..') { + while (in_array('..', $pathArray) && $pathArray[0] !== '..') { for ($i = 0; $i < count($pathArray); ++$i) { - if ($pathArray[$i] == '..' && $i > 0) { + if ($pathArray[$i] === '..' && $i > 0) { unset($pathArray[$i]); unset($pathArray[$i - 1]); break; @@ -71,7 +71,58 @@ class PHPWord_Shared_File $returnValue = implode('/', $pathArray); } - // Return return $returnValue; } -} + + /** + * PHP Words version of exif_imagetype to return the Image Type from a file + * + * @param string $filename + * @return int|bool + */ + private static function fallbackImagetype($filename) + { + if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) { + if ($type === 2) { + return self::IMAGETYPE_JPEG; + } elseif ($type === 1) { + return self::IMAGETYPE_GIF; + } elseif ($type === 3) { + return self::IMAGETYPE_PNG; + } elseif ($type === 6) { + return self::IMAGETYPE_BMP; + } elseif ($type === 7 || $type === 8) { + return self::IMAGETYPE_TIFF; + } + } + return false; + } + + /** + * Return the Image Type from a file + * + * @param string $filename + * @param bool $userFallbackFunction + * @return int|bool + */ + public static function imagetype($filename, $userFallbackFunction = false) + { + if ($userFallbackFunction || !function_exists('exif_imagetype')) { + return self::fallbackImagetype($filename); + } + + $imagetype = exif_imagetype($filename); + if ($imagetype === IMAGETYPE_JPEG) { + return self::IMAGETYPE_JPEG; + } elseif ($imagetype === IMAGETYPE_GIF) { + return self::IMAGETYPE_GIF; + } elseif ($imagetype === IMAGETYPE_PNG) { + return self::IMAGETYPE_PNG; + } elseif ($imagetype === IMAGETYPE_BMP) { + return self::IMAGETYPE_BMP; + } elseif ($imagetype === IMAGETYPE_TIFF_II || $imagetype === IMAGETYPE_TIFF_MM) { + return self::IMAGETYPE_TIFF; + } + return false; + } +} \ No newline at end of file diff --git a/Classes/PHPWord/Shared/Font.php b/Classes/PHPWord/Shared/Font.php index 3bb783b8..9d5a42a5 100755 --- a/Classes/PHPWord/Shared/Font.php +++ b/Classes/PHPWord/Shared/Font.php @@ -44,8 +44,8 @@ class PHPWord_Shared_Font /** * Calculate an (approximate) pixel size, based on inch size * - * @param int $sizeInInch Font size (in inch) - * @return int Size (in pixels) + * @param int $sizeInInch Font size (in inch) + * @return int Size (in pixels) */ public static function inchSizeToPixels($sizeInInch = 1) { @@ -55,24 +55,42 @@ class PHPWord_Shared_Font /** * Calculate an (approximate) pixel size, based on centimeter size * - * @param int $sizeInCm Font size (in centimeters) - * @return int Size (in pixels) + * @param int $sizeInCm Font size (in centimeters) + * @return int Size (in pixels) */ public static function centimeterSizeToPixels($sizeInCm = 1) { return ($sizeInCm * 37.795275591); } + /** + * Convert centimeter to twip + * + * @param int $sizeInCm + * @return int + */ public static function centimeterSizeToTwips($sizeInCm = 1) { return ($sizeInCm * 565.217); } + /** + * Convert inch to twip + * + * @param int $sizeInInch + * @return int + */ public static function inchSizeToTwips($sizeInInch = 1) { return self::centimeterSizeToTwips($sizeInInch * 2.54); } + /** + * Convert pixel to twip + * + * @param int $sizeInPixel + * @return int + */ public static function pixelSizeToTwips($sizeInPixel = 1) { return self::centimeterSizeToTwips($sizeInPixel / 37.795275591); diff --git a/Classes/PHPWord/Shared/XMLWriter.php b/Classes/PHPWord/Shared/XMLWriter.php index 6e6e6360..e86749d1 100755 --- a/Classes/PHPWord/Shared/XMLWriter.php +++ b/Classes/PHPWord/Shared/XMLWriter.php @@ -109,7 +109,7 @@ class PHPWord_Shared_XMLWriter /** * Get written data * - * @return $data + * @return string XML data */ public function getData() { @@ -124,8 +124,8 @@ class PHPWord_Shared_XMLWriter /** * Catch function calls (and pass them to internal XMLWriter) * - * @param unknown_type $function - * @param unknown_type $args + * @param mixed $function + * @param mixed $args */ public function __call($function, $args) { diff --git a/Classes/PHPWord/Shared/ZipStreamWrapper.php b/Classes/PHPWord/Shared/ZipStreamWrapper.php index fe4ff372..afebe7ef 100755 --- a/Classes/PHPWord/Shared/ZipStreamWrapper.php +++ b/Classes/PHPWord/Shared/ZipStreamWrapper.php @@ -71,6 +71,11 @@ class PHPWord_Shared_ZipStreamWrapper /** * Open stream + * + * @param string $path + * @param string $mode + * @param string $options + * @param string $opened_path */ public function stream_open($path, $mode, $options, &$opened_path) { @@ -119,6 +124,8 @@ class PHPWord_Shared_ZipStreamWrapper /** * Read stream + * + * @param int $count */ public function stream_read($count) { @@ -145,6 +152,9 @@ class PHPWord_Shared_ZipStreamWrapper /** * Seek stream + * + * @param int $offset + * @param mixed $whence */ public function stream_seek($offset, $whence) { diff --git a/Classes/PHPWord/Style.php b/Classes/PHPWord/Style.php index 8366b658..e82728e1 100755 --- a/Classes/PHPWord/Style.php +++ b/Classes/PHPWord/Style.php @@ -106,7 +106,9 @@ class PHPWord_Style * Add a table style * * @param string $styleName - * @param array $styles + * @param array $styleTable + * @param null|array $styleFirstRow + * @param null|array $styleLastRow */ public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null, $styleLastRow = null) { @@ -120,9 +122,9 @@ class PHPWord_Style /** * Add a title style * - * @param string $styleName + * @param int $titleCount * @param array $styleFont - * @param array $styleParagraph + * @param nullarray $styleParagraph */ public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) { @@ -143,7 +145,7 @@ class PHPWord_Style /** * Set default paragraph style * - * @param array $styles Paragraph style definition + * @param array $styles Paragraph style definition */ public static function setDefaultParagraphStyle($styles) { @@ -153,7 +155,7 @@ class PHPWord_Style /** * Get all styles * - * @return PHPWord_Style_Font[] + * @return array */ public static function getStyles() { @@ -163,8 +165,8 @@ class PHPWord_Style /** * Get style * - * @param string - * @return PHPWord_Style + * @param string $styleName + * @return null|PHPWord_Style */ public static function getStyle($styleName) { diff --git a/Classes/PHPWord/Style/Cell.php b/Classes/PHPWord/Style/Cell.php index b07eb4c2..2f733784 100755 --- a/Classes/PHPWord/Style/Cell.php +++ b/Classes/PHPWord/Style/Cell.php @@ -157,8 +157,8 @@ class PHPWord_Style_Cell /** * Set style value * - * @var string $key - * @var mixed $value + * @param string $key + * @param mixed $value */ public function setStyleValue($key, $value) { @@ -171,36 +171,65 @@ class PHPWord_Style_Cell } } + /** + * Get vertical align + */ public function getVAlign() { return $this->_valign; } + /** + * Set vertical align + * + * @param string $pValue + */ public function setVAlign($pValue = null) { $this->_valign = $pValue; } + /** + * Get text direction + */ public function getTextDirection() { return $this->_textDirection; } + /** + * Set text direction + * + * @param string $pValue + */ public function setTextDirection($pValue = null) { $this->_textDirection = $pValue; } + /** + * Get background color + */ public function getBgColor() { return $this->_bgColor; } + /** + * Set background color + * + * @param string $pValue + */ public function setBgColor($pValue = null) { $this->_bgColor = $pValue; } + /** + * Set border size + * + * @param int $pValue + */ public function setBorderSize($pValue = null) { $this->_borderTopSize = $pValue; @@ -209,6 +238,9 @@ class PHPWord_Style_Cell $this->_borderBottomSize = $pValue; } + /** + * Get border size + */ public function getBorderSize() { $t = $this->getBorderTopSize(); @@ -219,6 +251,11 @@ class PHPWord_Style_Cell return array($t, $l, $r, $b); } + /** + * Set border color + * + * @param string $pValue + */ public function setBorderColor($pValue = null) { $this->_borderTopColor = $pValue; @@ -227,6 +264,9 @@ class PHPWord_Style_Cell $this->_borderBottomColor = $pValue; } + /** + * Get border color + */ public function getBorderColor() { $t = $this->getBorderTopColor(); @@ -237,107 +277,189 @@ class PHPWord_Style_Cell return array($t, $l, $r, $b); } + /** + * Set border top size + * + * @param int $pValue + */ public function setBorderTopSize($pValue = null) { $this->_borderTopSize = $pValue; } + /** + * Get border top size + */ public function getBorderTopSize() { return $this->_borderTopSize; } + /** + * Set border top color + * + * @param string $pValue + */ public function setBorderTopColor($pValue = null) { $this->_borderTopColor = $pValue; } + /** + * Get border top color + */ public function getBorderTopColor() { return $this->_borderTopColor; } + /** + * Set border left size + * + * @param int $pValue + */ public function setBorderLeftSize($pValue = null) { $this->_borderLeftSize = $pValue; } + /** + * Get border left size + */ public function getBorderLeftSize() { return $this->_borderLeftSize; } + /** + * Set border left color + * + * @param string $pValue + */ public function setBorderLeftColor($pValue = null) { $this->_borderLeftColor = $pValue; } + /** + * Get border left color + */ public function getBorderLeftColor() { return $this->_borderLeftColor; } + /** + * Set border right size + * + * @param int $pValue + */ public function setBorderRightSize($pValue = null) { $this->_borderRightSize = $pValue; } + /** + * Get border right size + */ public function getBorderRightSize() { return $this->_borderRightSize; } + /** + * Set border right color + * + * @param string $pValue + */ public function setBorderRightColor($pValue = null) { $this->_borderRightColor = $pValue; } + /** + * Get border right color + */ public function getBorderRightColor() { return $this->_borderRightColor; } - + /** + * Set border bottom size + * + * @param int $pValue + */ public function setBorderBottomSize($pValue = null) { $this->_borderBottomSize = $pValue; } + /** + * Get border bottom size + */ public function getBorderBottomSize() { return $this->_borderBottomSize; } + /** + * Set border bottom color + * + * @param string $pValue + */ public function setBorderBottomColor($pValue = null) { $this->_borderBottomColor = $pValue; } + /** + * Get border bottom color + */ public function getBorderBottomColor() { return $this->_borderBottomColor; } + /** + * Get default border color + */ public function getDefaultBorderColor() { return $this->_defaultBorderColor; } + /** + * Set grid span (colspan) + * + * @param int $pValue + */ public function setGridSpan($pValue = null) { $this->_gridSpan = $pValue; } + /** + * Get grid span (colspan) + */ public function getGridSpan() { return $this->_gridSpan; } + /** + * Set vertical merge (rowspan) + * + * @param string $pValue + */ public function setVMerge($pValue = null) { $this->_vMerge = $pValue; } + /** + * Get vertical merge (rowspan) + */ public function getVMerge() { return $this->_vMerge; diff --git a/Classes/PHPWord/Style/Font.php b/Classes/PHPWord/Style/Font.php index f26f3924..2aa6cbc6 100755 --- a/Classes/PHPWord/Style/Font.php +++ b/Classes/PHPWord/Style/Font.php @@ -185,6 +185,8 @@ class PHPWord_Style_Font } /** + * Set style using associative array + * * @param array $style * @return $this */ @@ -510,6 +512,8 @@ class PHPWord_Style_Font } /** + * Get line height + * * @return int|float */ public function getLineHeight() diff --git a/Classes/PHPWord/Style/Image.php b/Classes/PHPWord/Style/Image.php index 9bec4d5b..a6a128c9 100755 --- a/Classes/PHPWord/Style/Image.php +++ b/Classes/PHPWord/Style/Image.php @@ -36,9 +36,32 @@ class PHPWord_Style_Image const WRAPPING_STYLE_BEHIND = 'behind'; const WRAPPING_STYLE_INFRONT = 'infront'; + /** + * Image width + * + * @var int + */ private $_width; + + /** + * Image width + * + * @var int + */ private $_height; + + /** + * Alignment + * + * @var string + */ private $_align; + + /** + * Wrapping style + * + * @var string + */ private $wrappingStyle; /** @@ -55,6 +78,9 @@ class PHPWord_Style_Image */ private $_marginLeft; + /** + * Constructor + */ public function __construct() { $this->_width = null; @@ -65,36 +91,66 @@ class PHPWord_Style_Image $this->setWrappingStyle(self::WRAPPING_STYLE_INLINE); } + /** + * Set style value + * + * @param string $key + * @param mixed $value + */ public function setStyleValue($key, $value) { $this->$key = $value; } + /** + * Get width + */ public function getWidth() { return $this->_width; } + /** + * Set width + * + * @param int $pValue + */ public function setWidth($pValue = null) { $this->_width = $pValue; } + /** + * Get height + */ public function getHeight() { return $this->_height; } + /** + * Set height + * + * @param int $pValue + */ public function setHeight($pValue = null) { $this->_height = $pValue; } + /** + * Get alignment + */ public function getAlign() { return $this->_align; } + /** + * Set alignment + * + * @param string $pValue + */ public function setAlign($pValue = null) { $this->_align = $pValue; @@ -145,6 +201,8 @@ class PHPWord_Style_Image } /** + * Set wrapping style + * * @param string $wrappingStyle * @throws InvalidArgumentException * @return $this @@ -167,6 +225,8 @@ class PHPWord_Style_Image } /** + * Get wrapping style + * * @return string */ public function getWrappingStyle() diff --git a/Classes/PHPWord/Style/Paragraph.php b/Classes/PHPWord/Style/Paragraph.php index 32a44929..14e1f8e0 100755 --- a/Classes/PHPWord/Style/Paragraph.php +++ b/Classes/PHPWord/Style/Paragraph.php @@ -133,6 +133,8 @@ class PHPWord_Style_Paragraph private $_pageBreakBefore = false; /** + * Set style using associative array + * * @param array $style * @return $this */ @@ -319,11 +321,11 @@ class PHPWord_Style_Paragraph return $this->_tabs; } - /* + /** * Set tabs * - * @param array $pValue - * @return PHPWord_Style_Paragraph + * @param array $pValue + * @return PHPWord_Style_Paragraph */ public function setTabs($pValue = null) { @@ -500,6 +502,8 @@ class PHPWord_Style_Paragraph } /** + * Get line height + * * @return int|float */ public function getLineHeight() diff --git a/Classes/PHPWord/Style/Row.php b/Classes/PHPWord/Style/Row.php index 93b5f862..da039d84 100644 --- a/Classes/PHPWord/Style/Row.php +++ b/Classes/PHPWord/Style/Row.php @@ -54,12 +54,21 @@ class PHPWord_Style_Row /** * Set style value + * + * @param string $key + * @param mixed $value */ public function setStyleValue($key, $value) { $this->$key = $value; } + /** + * Set tblHeader + * + * @param boolean $pValue + * @return PHPWord_Style_Row + */ public function setTblHeader($pValue = false) { if (!is_bool($pValue)) { @@ -69,11 +78,22 @@ class PHPWord_Style_Row return $this; } + /** + * Get tblHeader + * + * @return boolean + */ public function getTblHeader() { return $this->_tblHeader; } + /** + * Set cantSplit + * + * @param boolean $pValue + * @return PHPWord_Style_Row + */ public function setCantSplit($pValue = false) { if (!is_bool($pValue)) { @@ -83,6 +103,11 @@ class PHPWord_Style_Row return $this; } + /** + * Get cantSplit + * + * @return boolean + */ public function getCantSplit() { return $this->_cantSplit; diff --git a/Classes/PHPWord/Style/Table.php b/Classes/PHPWord/Style/Table.php index c3ef2e01..223e31c2 100755 --- a/Classes/PHPWord/Style/Table.php +++ b/Classes/PHPWord/Style/Table.php @@ -30,12 +30,37 @@ */ class PHPWord_Style_Table { - + /** + * Cell margin top + * + * @var int + */ private $_cellMarginTop; + + /** + * Cell margin left + * + * @var int + */ private $_cellMarginLeft; + + /** + * Cell margin right + * + * @var int + */ private $_cellMarginRight; + + /** + * Cell margin bottom + * + * @var int + */ private $_cellMarginBottom; + /** + * Constructor + */ public function __construct() { $this->_cellMarginTop = null; @@ -44,51 +69,92 @@ class PHPWord_Style_Table $this->_cellMarginBottom = null; } + /** + * Set style value + * + * @param string $key + * @param mixed $value + */ public function setStyleValue($key, $value) { $this->$key = $value; } + /** + * Set cell margin top + * + * @param int $pValue + */ public function setCellMarginTop($pValue = null) { $this->_cellMarginTop = $pValue; } + /** + * Get cell margin top + */ public function getCellMarginTop() { return $this->_cellMarginTop; } + /** + * Set cell margin left + * + * @param int $pValue + */ public function setCellMarginLeft($pValue = null) { $this->_cellMarginLeft = $pValue; } + /** + * Get cell margin left + */ public function getCellMarginLeft() { return $this->_cellMarginLeft; } + /** + * Set cell margin right + * + * @param int $pValue + */ public function setCellMarginRight($pValue = null) { $this->_cellMarginRight = $pValue; } + /** + * Get cell margin right + */ public function getCellMarginRight() { return $this->_cellMarginRight; } + /** + * Set cell margin bottom + * + * @param int $pValue + */ public function setCellMarginBottom($pValue = null) { $this->_cellMarginBottom = $pValue; } + /** + * Get cell margin bottom + */ public function getCellMarginBottom() { return $this->_cellMarginBottom; } + /** + * Get cell margin + */ public function getCellMargin() { return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); diff --git a/Classes/PHPWord/Style/TableFull.php b/Classes/PHPWord/Style/TableFull.php index 573ae53b..8d145366 100755 --- a/Classes/PHPWord/Style/TableFull.php +++ b/Classes/PHPWord/Style/TableFull.php @@ -30,7 +30,6 @@ */ class PHPWord_Style_TableFull { - /** * Style for first row * @@ -160,6 +159,10 @@ class PHPWord_Style_TableFull /** * Create a new TableFull Font + * + * @param null|array $styleTable + * @param null|array $styleFirstRow + * @param null|array $styleLastRow */ public function __construct($styleTable = null, $styleFirstRow = null, $styleLastRow = null) { @@ -234,11 +237,19 @@ class PHPWord_Style_TableFull return $this->_lastRow; } + /** + * Get background color + */ public function getBgColor() { return $this->_bgColor; } + /** + * Set background color + * + * @param string $pValue + */ public function setBgColor($pValue = null) { $this->_bgColor = $pValue; @@ -247,7 +258,7 @@ class PHPWord_Style_TableFull /** * Set TLRBVH Border Size * - * @param int $pValue Border size in eighths of a point (1/8 point) + * @param int $pValue Border size in eighths of a point (1/8 point) */ public function setBorderSize($pValue = null) { @@ -278,6 +289,8 @@ class PHPWord_Style_TableFull /** * Set TLRBVH Border Color + * + * @param string $pValue */ public function setBorderColor($pValue = null) { @@ -306,161 +319,293 @@ class PHPWord_Style_TableFull return array($t, $l, $r, $b, $h, $v); } + /** + * Set border top size + * + * @param int $pValue + */ public function setBorderTopSize($pValue = null) { $this->_borderTopSize = $pValue; } + /** + * Get border top size + */ public function getBorderTopSize() { return $this->_borderTopSize; } + /** + * Set border top color + * + * @param string $pValue + */ public function setBorderTopColor($pValue = null) { $this->_borderTopColor = $pValue; } + /** + * Get border top color + */ public function getBorderTopColor() { return $this->_borderTopColor; } + /** + * Set border left size + * + * @param int $pValue + */ public function setBorderLeftSize($pValue = null) { $this->_borderLeftSize = $pValue; } + /** + * Get border left size + */ public function getBorderLeftSize() { return $this->_borderLeftSize; } + /** + * Set border left color + * + * @param string $pValue + */ public function setBorderLeftColor($pValue = null) { $this->_borderLeftColor = $pValue; } + /** + * Get border left color + */ public function getBorderLeftColor() { return $this->_borderLeftColor; } + /** + * Set border right size + * + * @param int $pValue + */ public function setBorderRightSize($pValue = null) { $this->_borderRightSize = $pValue; } + /** + * Get border right size + * + * @param int $pValue + */ public function getBorderRightSize() { return $this->_borderRightSize; } + /** + * Set border right color + * + * @param string $pValue + */ public function setBorderRightColor($pValue = null) { $this->_borderRightColor = $pValue; } + /** + * Get border right color + */ public function getBorderRightColor() { return $this->_borderRightColor; } + /** + * Set border bottom size + * + * + * @param string $pValue + * @param int $pValue + */ public function setBorderBottomSize($pValue = null) { $this->_borderBottomSize = $pValue; } + /** + * Get border bottom size + */ public function getBorderBottomSize() { return $this->_borderBottomSize; } + /** + * Set border bottom color + * + * @param string $pValue + */ public function setBorderBottomColor($pValue = null) { $this->_borderBottomColor = $pValue; } + /** + * Get border bottom color + */ public function getBorderBottomColor() { return $this->_borderBottomColor; } + /** + * Set border inside horizontal color + * + * @param string $pValue + */ public function setBorderInsideHColor($pValue = null) { $this->_borderInsideHColor = $pValue; } + /** + * Get border inside horizontal color + */ public function getBorderInsideHColor() { return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null; } + /** + * Set border inside vertical color + * + * @param string $pValue + */ public function setBorderInsideVColor($pValue = null) { $this->_borderInsideVColor = $pValue; } + /** + * Get border inside vertical color + */ public function getBorderInsideVColor() { return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null; } + /** + * Set border inside horizontal size + * + * @param int $pValue + */ public function setBorderInsideHSize($pValue = null) { $this->_borderInsideHSize = $pValue; } + /** + * Get border inside horizontal size + */ public function getBorderInsideHSize() { return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null; } + /** + * Set border inside vertical size + * + * @param int $pValue + */ public function setBorderInsideVSize($pValue = null) { $this->_borderInsideVSize = $pValue; } + /** + * Get border inside vertical size + */ public function getBorderInsideVSize() { return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null; } + /** + * Set cell margin top + * + * @param int $pValue + */ public function setCellMarginTop($pValue = null) { $this->_cellMarginTop = $pValue; } + /** + * Get cell margin top + */ public function getCellMarginTop() { return $this->_cellMarginTop; } + /** + * Set cell margin left + * + * @param int $pValue + */ public function setCellMarginLeft($pValue = null) { $this->_cellMarginLeft = $pValue; } + /** + * Get cell margin left + */ public function getCellMarginLeft() { return $this->_cellMarginLeft; } + /** + * Set cell margin right + * + * @param int $pValue + */ public function setCellMarginRight($pValue = null) { $this->_cellMarginRight = $pValue; } + /** + * Get cell margin right + */ public function getCellMarginRight() { return $this->_cellMarginRight; } + /** + * Set cell margin bottom + * + * @param int $pValue + */ public function setCellMarginBottom($pValue = null) { $this->_cellMarginBottom = $pValue; } + /** + * Get cell margin bottom + */ public function getCellMarginBottom() { return $this->_cellMarginBottom; @@ -479,6 +624,9 @@ class PHPWord_Style_TableFull $this->_cellMarginBottom = $pValue; } + /** + * Get cell margin + */ public function getCellMargin() { return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom); diff --git a/Classes/PHPWord/Style/Tabs.php b/Classes/PHPWord/Style/Tabs.php index a5e1a8bb..ece1315f 100755 --- a/Classes/PHPWord/Style/Tabs.php +++ b/Classes/PHPWord/Style/Tabs.php @@ -39,6 +39,7 @@ class PHPWord_Style_Tabs private $_tabs; /** + * Constructor * * @param array $tabs */ @@ -48,6 +49,7 @@ class PHPWord_Style_Tabs } /** + * Convert to XML * * @param PHPWord_Shared_XMLWriter $objWriter */ diff --git a/Classes/PHPWord/TOC.php b/Classes/PHPWord/TOC.php index c81fca22..499fdd64 100755 --- a/Classes/PHPWord/TOC.php +++ b/Classes/PHPWord/TOC.php @@ -105,6 +105,8 @@ class PHPWord_TOC /** * Add a Title * + * @param string $text + * @param int $depth * @return array */ public static function addTitle($text, $depth = 0) diff --git a/Classes/PHPWord/Writer/IWriter.php b/Classes/PHPWord/Writer/IWriter.php index f5ca8299..d00d2d40 100755 --- a/Classes/PHPWord/Writer/IWriter.php +++ b/Classes/PHPWord/Writer/IWriter.php @@ -33,8 +33,8 @@ interface PHPWord_Writer_IWriter /** * Save PHPWord to file * - * @param string $pFileName - * @throws Exception + * @param string $pFilename + * @throws Exception */ public function save($pFilename = null); } diff --git a/Classes/PHPWord/Writer/ODText.php b/Classes/PHPWord/Writer/ODText.php index 7d8c2e4b..e8ab61ee 100755 --- a/Classes/PHPWord/Writer/ODText.php +++ b/Classes/PHPWord/Writer/ODText.php @@ -68,7 +68,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter /** * Create a new PHPWord_Writer_ODText * - * @param PHPWord $pPHPWord + * @param PHPWord $pPHPWord */ public function __construct(PHPWord $pPHPWord = null) { @@ -98,8 +98,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter /** * Save PHPWord to file * - * @param string $pFileName - * @throws Exception + * @param string $pFilename + * @throws Exception */ public function save($pFilename = null) { @@ -212,8 +212,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter /** * Get PHPWord object * - * @param PHPWord $pPHPWord PHPWord object - * @throws Exception + * @param PHPWord $pPHPWord PHPWord object + * @throws Exception * @return PHPWord_Writer_ODText */ public function setPHPWord(PHPWord $pPHPWord = null) @@ -226,6 +226,7 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter * Get PHPWord_Worksheet_BaseDrawing HashTable * * @return PHPWord_HashTable + * @codeCoverageIgnore */ public function getDrawingHashTable() { @@ -235,8 +236,8 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter /** * Get writer part * - * @param string $pPartName Writer part name - * @return PHPWord_Writer_ODText_WriterPart + * @param string $pPartName Writer part name + * @return PHPWord_Writer_ODText_WriterPart */ public function getWriterPart($pPartName = '') { @@ -260,9 +261,9 @@ class PHPWord_Writer_ODText implements PHPWord_Writer_IWriter /** * Set use disk caching where possible? * - * @param boolean $pValue - * @param string $pDirectory Disk caching directory - * @throws Exception Exception when directory does not exist + * @param boolean $pValue + * @param string $pDirectory Disk caching directory + * @throws Exception Exception when directory does not exist * @return PHPWord_Writer_ODText */ public function setUseDiskCaching($pValue = false, $pDirectory = null) diff --git a/Classes/PHPWord/Writer/ODText/Content.php b/Classes/PHPWord/Writer/ODText/Content.php index 0899990b..772e5408 100755 --- a/Classes/PHPWord/Writer/ODText/Content.php +++ b/Classes/PHPWord/Writer/ODText/Content.php @@ -33,9 +33,9 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart /** * Write content file to XML format * - * @param PHPWord $pPHPWord - * @return string XML Output - * @throws Exception + * @param PHPWord $pPHPWord + * @return string XML Output + * @throws Exception */ public function writeContent(PHPWord $pPHPWord = null) { @@ -344,9 +344,9 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart /** * Write TextRun section * - * @param PHPWord_Shared_XMLWriter $objWriter - * @param PHPWord_Section_TextRun $textrun - * @todo Enable all other section types + * @param PHPWord_Shared_XMLWriter $objWriter + * @param PHPWord_Section_TextRun $textrun + * @todo Enable all other section types */ protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) { @@ -364,6 +364,8 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart /** * Write TextBreak + * + * @param PHPWord_Shared_XMLWriter $objWriter */ protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null) { @@ -373,10 +375,22 @@ class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart } // @codeCoverageIgnoreStart + /** + * Write end section + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param PHPWord_Section $section + */ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) { } + /** + * Write section + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param PHPWord_Section $section + */ private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null) { } diff --git a/Classes/PHPWord/Writer/ODText/Manifest.php b/Classes/PHPWord/Writer/ODText/Manifest.php index 89e802dc..0d627ec9 100755 --- a/Classes/PHPWord/Writer/ODText/Manifest.php +++ b/Classes/PHPWord/Writer/ODText/Manifest.php @@ -113,9 +113,10 @@ class PHPWord_Writer_ODText_Manifest extends PHPWord_Writer_ODText_WriterPart /** * Get image mime type * - * @param string $pFile Filename - * @return string Mime Type - * @throws Exception + * @param string $pFile Filename + * @return string Mime Type + * @throws Exception + * @codeCoverageIgnore Image is not yet handled by ODText */ private function _getImageMimeType($pFile = '') { diff --git a/Classes/PHPWord/Writer/RTF.php b/Classes/PHPWord/Writer/RTF.php index a090fb17..03aee542 100755 --- a/Classes/PHPWord/Writer/RTF.php +++ b/Classes/PHPWord/Writer/RTF.php @@ -44,14 +44,31 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter */ private $_drawingHashTable; + /** + * Color table + * + * @var array + */ private $_colorTable; + + /** + * Font table + * + * @var array + */ private $_fontTable; + + /** + * Last paragraph style + * + * @var PHPWord_Style_Paragraph + */ private $_lastParagraphStyle; /** * Create a new PHPWord_Writer_ODText * - * @param PHPWord $pPHPWord + * @param PHPWord $pPHPWord */ public function __construct(PHPWord $pPHPWord = null) { @@ -65,8 +82,8 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter /** * Save PHPWord to file * - * @param string $pFileName - * @throws Exception + * @param string $pFilename + * @throws Exception */ public function save($pFilename = null) { @@ -115,8 +132,8 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter /** * Get PHPWord object * - * @param PHPWord $pPHPWord PHPWord object - * @throws Exception + * @param PHPWord $pPHPWord PHPWord object + * @throws Exception * @return PHPWord_Writer_RTF */ public function setPHPWord(PHPWord $pPHPWord = null) @@ -129,12 +146,18 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter * Get PHPWord_Worksheet_BaseDrawing HashTable * * @return PHPWord_HashTable + * @codeCoverageIgnore */ public function getDrawingHashTable() { return $this->_drawingHashTable; } + /** + * Get document data + * + * @return string + */ private function getData() { // PHPWord object : $this->_document @@ -188,6 +211,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter return $sRTFContent; } + /** + * Get font table + * + * @return array + */ private function getDataFont() { $pPHPWord = $this->_document; @@ -238,6 +266,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter return $arrFonts; } + /** + * Get color tables + * + * @return array + */ private function getDataColor() { $pPHPWord = $this->_document; @@ -294,6 +327,11 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter return $arrColors; } + /** + * Get content + * + * @return string + */ private function getDataContent() { $pPHPWord = $this->_document; @@ -342,6 +380,10 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter /** * Get text + * + * @param PHPWord_Section_Text $text + * @param boolean $withoutP + * @return string */ private function getDataContentText(PHPWord_Section_Text $text, $withoutP = false) { @@ -428,11 +470,15 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter if (!$withoutP) { $sRTFText .= '\par' . PHP_EOL; } + return $sRTFText; } /** * Get text run content + * + * @param PHPWord_Section_TextRun $textrun + * @return string */ private function getDataContentTextRun(PHPWord_Section_TextRun $textrun) { @@ -449,9 +495,15 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter } $sRTFText .= '\par' . PHP_EOL; } + return $sRTFText; } + /** + * Get text break + * + * @return string + */ private function getDataContentTextBreak() { $this->_lastParagraphStyle = ''; @@ -463,6 +515,7 @@ class PHPWord_Writer_RTF implements PHPWord_Writer_IWriter * Write unsupported element * * @param string $element + * @return string */ private function getDataContentUnsupportedElement($element) { diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index e62341bf..16d66c66 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -24,7 +24,6 @@ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version 0.8.0 */ - use PhpOffice\PhpWord\Exceptions\InvalidImageException; use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException; @@ -33,15 +32,54 @@ use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException; */ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter { - + /** + * PHPWord object + * + * @var PHPWord + */ private $_document; + + /** + * Writer parts + * + * @var array + */ private $_writerParts; + + /** + * Directory for caching + * + * @var string + */ private $_diskCachingDirectory; + + /** + * Use disk caching + * + * @var boolean + */ private $_useDiskCaching = false; + + /** + * Image types + * + * @var array + */ private $_imageTypes = array(); + + /** + * Object types + * + * @var array + */ private $_objectTypes = array(); - public function __construct(PHPWord $PHPWord = null) + /** + * Constructor + * + * @param PHPWord $PHPWord + */ + public function __construct(PHPWord $PHPWord = null) { $this->_document = $PHPWord; @@ -63,6 +101,11 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter } } + /** + * Save + * + * @param string $pFilename + */ public function save($pFilename = null) { if (!is_null($this->_document)) { @@ -204,6 +247,8 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter } /** + * Check content types + * * @param string $src */ private function checkContentTypes($src) @@ -212,21 +257,10 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter if (stripos(strrev($src), strrev('.php')) === 0) { $extension = 'php'; } else { - $imageType = exif_imagetype($src); - if ($imageType === IMAGETYPE_JPEG) { - $extension = 'jpg'; - } elseif ($imageType === IMAGETYPE_GIF) { - $extension = 'gif'; - } elseif ($imageType === IMAGETYPE_PNG) { - $extension = 'png'; - } elseif ($imageType === IMAGETYPE_BMP) { - $extension = 'bmp'; - } elseif ($imageType === IMAGETYPE_TIFF_II || $imageType === IMAGETYPE_TIFF_MM) { - $extension = 'tif'; - } + $extension = PHPWord_Shared_File::imagetype($src); } - if (isset($extension)) { + if (isset($extension) && $extension) { $imageData = getimagesize($src); $imageType = image_type_to_mime_type($imageData[2]); $imageExtension = str_replace('.', '', image_type_to_extension($imageData[2])); @@ -236,13 +270,16 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter if (!in_array($imageType, $this->_imageTypes)) { $this->_imageTypes[$imageExtension] = $imageType; } - } else { - if (!in_array($extension, $this->_objectTypes)) { - $this->_objectTypes[] = $extension; - } + } elseif (!in_array($extension, $this->_objectTypes)) { + $this->_objectTypes[] = $extension; } } + /** + * Get writer part + * + * @param string $pPartName + */ public function getWriterPart($pPartName = '') { if ($pPartName != '' && isset($this->_writerParts[strtolower($pPartName)])) { @@ -252,11 +289,20 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter } } + /** + * Get use disk catching setting + */ public function getUseDiskCaching() { return $this->_useDiskCaching; } + /** + * Set use disk catching setting + * + * @param boolean $pValue + * @param string $pDirectory + */ public function setUseDiskCaching($pValue = false, $pDirectory = null) { $this->_useDiskCaching = $pValue; @@ -272,6 +318,12 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter return $this; } + /** + * Add file to package + * + * @param mixed $objZip + * @param array $element + */ private function _addFileToPackage($objZip, $element) { if (isset($element['isMemImage']) && $element['isMemImage']) { @@ -289,4 +341,14 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter $this->checkContentTypes($element['source']); } } + + /** + * Get disk caching directory + * + * @return string + */ + public function getDiskCachingDirectory() + { + return $this->_diskCachingDirectory; + } } diff --git a/Classes/PHPWord/Writer/Word2007/Base.php b/Classes/PHPWord/Writer/Word2007/Base.php index e9249120..d829bf92 100755 --- a/Classes/PHPWord/Writer/Word2007/Base.php +++ b/Classes/PHPWord/Writer/Word2007/Base.php @@ -31,9 +31,10 @@ */ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart { - /** * Write text + * + * @param boolean $withoutP */ protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { @@ -232,6 +233,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * Write link + * + * @param boolean $withoutP */ protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) { @@ -791,8 +794,11 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart } /** + * Write image + * * @param \PHPWord_Shared_XMLWriter $objWriter * @param \PHPWord_Section_Image|\PHPWord_Section_MemoryImage $image + * @param boolean $withoutP */ protected function _writeImage(PHPWord_Shared_XMLWriter $objWriter = null, $image, $withoutP = false) { @@ -873,6 +879,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * Write watermark + * + * @param PHP_Section_Image|PHP_Section_MemoryImage $image */ protected function _writeWatermark(PHPWord_Shared_XMLWriter $objWriter = null, $image) { @@ -1003,6 +1011,8 @@ class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart /** * Write footnote reference + * + * @param boolean $withoutP */ protected function _writeFootnoteReference(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Footnote $footnote, $withoutP = false) { diff --git a/Classes/PHPWord/Writer/Word2007/ContentTypes.php b/Classes/PHPWord/Writer/Word2007/ContentTypes.php index 8a6e39ef..26032ae1 100755 --- a/Classes/PHPWord/Writer/Word2007/ContentTypes.php +++ b/Classes/PHPWord/Writer/Word2007/ContentTypes.php @@ -30,7 +30,15 @@ */ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_WriterPart { - + /** + * Write contenttypes.xml + * + * @param array $_imageTypes + * @param array $_objectTypes + * @param int $_cHdrs + * @param array $footers + * @return string XML data + */ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers) { // Create XML writer @@ -163,7 +171,6 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write } } - $objWriter->endElement(); // Return @@ -173,9 +180,9 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write /** * Get image mime type * - * @param string $pFile Filename - * @return string Mime Type - * @throws Exception + * @param string $pFile Filename + * @return string Mime Type + * @throws Exception */ private function _getImageMimeType($pFile = '') { @@ -190,10 +197,10 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write /** * Write Default content type * - * @param PHPWord_Shared_XMLWriter $objWriter XML Writer - * @param string $pPartname Part name - * @param string $pContentType Content type - * @throws Exception + * @param PHPWord_Shared_XMLWriter $objWriter XML Writer + * @param string $pPartname Part name + * @param string $pContentType Content type + * @throws Exception */ private function _writeDefaultContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') { @@ -211,10 +218,10 @@ class PHPWord_Writer_Word2007_ContentTypes extends PHPWord_Writer_Word2007_Write /** * Write Override content type * - * @param PHPWord_Shared_XMLWriter $objWriter XML Writer - * @param string $pPartname Part name - * @param string $pContentType Content type - * @throws Exception + * @param PHPWord_Shared_XMLWriter $objWriter XML Writer + * @param string $pPartname Part name + * @param string $pContentType Content type + * @throws Exception */ private function _writeOverrideContentType(PHPWord_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') { diff --git a/Classes/PHPWord/Writer/Word2007/DocProps.php b/Classes/PHPWord/Writer/Word2007/DocProps.php index 2e8f8b5a..b2ec6f39 100755 --- a/Classes/PHPWord/Writer/Word2007/DocProps.php +++ b/Classes/PHPWord/Writer/Word2007/DocProps.php @@ -30,7 +30,12 @@ */ class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart { - + /** + * Write app.xml + * + * @param PHPWord $pPHPWord + * @return string XML data + */ public function writeDocPropsApp(PHPWord $pPHPWord = null) { // Create XML writer @@ -122,7 +127,12 @@ class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPar return $objWriter->getData(); } - + /** + * Write core.xml + * + * @param PHPWord $pPHPWord + * @return string XML data + */ public function writeDocPropsCore(PHPWord $pPHPWord = null) { // Create XML writer diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index abdd92cc..1bd86152 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -30,7 +30,9 @@ */ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base { - + /** + * Write document.xml + */ public function writeDocument(PHPWord $pPHPWord = null) { // Create XML writer @@ -114,6 +116,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base return $objWriter->getData(); } + /** + * Write section start + */ private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) { $objWriter->startElement('w:p'); @@ -123,6 +128,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } + /** + * Write section end + */ private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section) { $settings = $section->getSettings(); @@ -256,6 +264,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } + /** + * Write page break element + */ private function _writePageBreak(PHPWord_Shared_XMLWriter $objWriter = null) { $objWriter->startElement('w:p'); @@ -267,6 +278,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } + /** + * Write list item element + */ public function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem) { $textObject = $listItem->getTextObject(); @@ -306,6 +320,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } + /** + * Write object element + */ protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object) { $rIdObject = $object->getRelationId(); @@ -365,6 +382,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); // w:p } + /** + * Write TOC element + */ private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null) { $titles = PHPWord_TOC::getTitles(); diff --git a/Classes/PHPWord/Writer/Word2007/DocumentRels.php b/Classes/PHPWord/Writer/Word2007/DocumentRels.php index 9817a31f..eda62c5e 100755 --- a/Classes/PHPWord/Writer/Word2007/DocumentRels.php +++ b/Classes/PHPWord/Writer/Word2007/DocumentRels.php @@ -30,7 +30,12 @@ */ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_WriterPart { - + /** + * Write word/_rels/document.xml.rels + * + * @param array $_relsCollection + * @return string XML data + */ public function writeDocumentRels($_relsCollection) { // Create XML writer @@ -119,6 +124,12 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write return $objWriter->getData(); } + /** + * Write word/_rels/(header|footer)(\d).xml.rels + * + * @param array $_relsCollection + * @return string XML data + */ public function writeHeaderFooterRels($_relsCollection) { // Create XML writer @@ -150,13 +161,21 @@ class PHPWord_Writer_Word2007_DocumentRels extends PHPWord_Writer_Word2007_Write ); } - $objWriter->endElement(); // Return return $objWriter->getData(); } + /** + * Write individual relations + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param int $pId + * @param string $pType + * @param string $pTarget + * @param string $pTargetMode + */ private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { diff --git a/Classes/PHPWord/Writer/Word2007/Footer.php b/Classes/PHPWord/Writer/Word2007/Footer.php index 6ee18d66..ef81fdb0 100755 --- a/Classes/PHPWord/Writer/Word2007/Footer.php +++ b/Classes/PHPWord/Writer/Word2007/Footer.php @@ -30,7 +30,12 @@ */ class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base { - + /** + * Write footer + * + * @param PHPWord_Section_Footer $footer + * @return string XML data + */ public function writeFooter(PHPWord_Section_Footer $footer) { // Create XML writer diff --git a/Classes/PHPWord/Writer/Word2007/Footnotes.php b/Classes/PHPWord/Writer/Word2007/Footnotes.php index 28d087c7..5d0680ce 100644 --- a/Classes/PHPWord/Writer/Word2007/Footnotes.php +++ b/Classes/PHPWord/Writer/Word2007/Footnotes.php @@ -25,9 +25,17 @@ * @version 0.8.0 */ - +/** + * Class PHPWord_Writer_Word2007_Footnotes + */ class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base { + /** + * Write footnotes.xml + * + * @param array $allFootnotesCollection + * @return string XML data + */ public function writeFootnotes($allFootnotesCollection) { // Create XML writer diff --git a/Classes/PHPWord/Writer/Word2007/FootnotesRels.php b/Classes/PHPWord/Writer/Word2007/FootnotesRels.php index 0e562b59..48721985 100644 --- a/Classes/PHPWord/Writer/Word2007/FootnotesRels.php +++ b/Classes/PHPWord/Writer/Word2007/FootnotesRels.php @@ -25,9 +25,16 @@ * @version 0.8.0 */ - +/** + * Class PHPWord_Writer_Word2007_FootnotesRels + */ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_WriterPart { + /** + * Write footnotes relationships + * + * @param array $_relsCollection + */ public function writeFootnotesRels($_relsCollection) { // Create XML writer @@ -61,6 +68,15 @@ class PHPWord_Writer_Word2007_FootnotesRels extends PHPWord_Writer_Word2007_Writ return $objWriter->getData(); } + /** + * Write individual relations + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param int $pId + * @param string $pType + * @param string $pTarget + * @param string $pTargetMode + */ private function _writeRelationship(PHPWord_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') { if ($pType != '' && $pTarget != '') { diff --git a/Classes/PHPWord/Writer/Word2007/Header.php b/Classes/PHPWord/Writer/Word2007/Header.php index 59eebd91..0c11183b 100755 --- a/Classes/PHPWord/Writer/Word2007/Header.php +++ b/Classes/PHPWord/Writer/Word2007/Header.php @@ -30,7 +30,12 @@ */ class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base { - + /** + * Write header + * + * @param PHPWord_Section_Header $header + * @return string XML data + */ public function writeHeader(PHPWord_Section_Header $header) { // Create XML writer diff --git a/Classes/PHPWord/Writer/Word2007/Rels.php b/Classes/PHPWord/Writer/Word2007/Rels.php index 06eb59cc..9304bda6 100755 --- a/Classes/PHPWord/Writer/Word2007/Rels.php +++ b/Classes/PHPWord/Writer/Word2007/Rels.php @@ -30,7 +30,11 @@ */ class PHPWord_Writer_Word2007_Rels extends PHPWord_Writer_Word2007_WriterPart { - + /** + * Write _rels/.rels + * + * @param PHPWord $pPHPWord + */ public function writeRelationships(PHPWord $pPHPWord = null) { // Create XML writer diff --git a/Classes/PHPWord/Writer/Word2007/Styles.php b/Classes/PHPWord/Writer/Word2007/Styles.php index 3724323e..1f61051a 100755 --- a/Classes/PHPWord/Writer/Word2007/Styles.php +++ b/Classes/PHPWord/Writer/Word2007/Styles.php @@ -30,9 +30,18 @@ */ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base { - + /** + * PHPWord object + * + * @var PHPWord + */ private $_document; + /** + * Write styles + * + * @param PHPWord $pPHPWord + */ public function writeStyles(PHPWord $pPHPWord = null) { // Create XML writer @@ -181,6 +190,12 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base return $objWriter->getData(); } + /** + * Write style + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param PHPWord_Style_TableFull $style + */ private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style) { @@ -302,6 +317,13 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base } } + /** + * Write row style + * + * @param PHPWord_Shared_XMLWriter $objWriter + * @param string $type + * @param PHPWord_Style_TableFull $style + */ private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_TableFull $style) { $brdSz = $style->getBorderSize(); @@ -362,7 +384,11 @@ class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base $objWriter->endElement(); } - + /** + * Write doc defaults + * + * @param PHPWord_Shared_XMLWriter $objWriter + */ private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null) { $fontName = $this->_document->getDefaultFontName(); diff --git a/Classes/PHPWord/Writer/Word2007/WriterPart.php b/Classes/PHPWord/Writer/Word2007/WriterPart.php index cc004254..35cf348f 100755 --- a/Classes/PHPWord/Writer/Word2007/WriterPart.php +++ b/Classes/PHPWord/Writer/Word2007/WriterPart.php @@ -30,13 +30,28 @@ */ abstract class PHPWord_Writer_Word2007_WriterPart { + /** + * Parent writer object + * + * @var PHPWord_Writer_Word2007 + */ private $_parentWriter; + /** + * Set parent writer + * + * @param PHPWord_Writer_IWriter + */ public function setParentWriter(PHPWord_Writer_IWriter $pWriter = null) { $this->_parentWriter = $pWriter; } + /** + * Get parent writer + * + * @return PHPWord_Writer_IWriter + */ public function getParentWriter() { if (!is_null($this->_parentWriter)) { diff --git a/Tests/PHPWord/Shared/FileTest.php b/Tests/PHPWord/Shared/FileTest.php index a5ac348f..fe825b8f 100644 --- a/Tests/PHPWord/Shared/FileTest.php +++ b/Tests/PHPWord/Shared/FileTest.php @@ -54,4 +54,39 @@ class FileTest extends \PHPUnit_Framework_TestCase $expected = $dir . DIRECTORY_SEPARATOR . $file; $this->assertEquals($expected, PHPWord_Shared_File::realpath($file)); } -} + + /** + * @covers PHPWord_Shared_File::imagetype + * @covers PHPWord_Shared_File::fallbackImagetype + */ + public function testImagetype() + { + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif"; + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename, true)); + $this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename)); + + $filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx"; + $this->assertFalse(PHPWord_Shared_File::imagetype($filename, true)); + $this->assertFalse(PHPWord_Shared_File::imagetype($filename)); + } +} \ No newline at end of file diff --git a/Tests/PHPWord/TemplateTest.php b/Tests/PHPWord/TemplateTest.php index 872ab182..1439cebc 100644 --- a/Tests/PHPWord/TemplateTest.php +++ b/Tests/PHPWord/TemplateTest.php @@ -145,17 +145,43 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase @$template->applyXslStyleSheet($xslDOMDocument); } + /** + * @covers PHPWord_Template + */ + public function testConstruct() + { + $template = \join( + \DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx') + ); + $expectedVar = array('tableHeader', 'userId', 'userName'); + $document = new PHPWord_Template($template); + $actualVar = $document->getVariables(); + $document->cloneRow('userId', 9); + $document->setValue('userId#1', utf8_decode('ééé')); + $document->setValue('userId#2', 'a'); + $document->setValue('userId#3', 'a'); + $document->setValue('userId#3', 'a'); + $document->setValue('userId#4', 'a'); + $document->setValue('userId#5', 'a'); + $document->setValue('userId#6', 'a'); + $document->setValue('userId#7', 'a'); + $document->setValue('userId#8', 'a'); + $document->cloneRow('userId#9', 'a'); + $this->assertEquals($expectedVar, $actualVar); + } + /** * @covers ::setValue * @covers ::getVariables * @covers ::cloneRow * @covers ::saveAs */ - public function testCloneRow() + public function testCloneMergedRow() { $template = \join( \DIRECTORY_SEPARATOR, - array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-row.docx') + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'clone-merge.docx') ); $expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation'); $docName = 'clone-test-result.docx'; diff --git a/Tests/PHPWord/Writer/ODText/WriterPartTest.php b/Tests/PHPWord/Writer/ODText/WriterPartTest.php new file mode 100644 index 00000000..f7b70ba2 --- /dev/null +++ b/Tests/PHPWord/Writer/ODText/WriterPartTest.php @@ -0,0 +1,45 @@ +getMockForAbstractClass( + 'PHPWord_Writer_Word2007_WriterPart' + ); + $object->setParentWriter(new PHPWord_Writer_ODText()); + $this->assertEquals( + new PHPWord_Writer_ODText(), + $object->getParentWriter() + ); + } + + /** + * covers ::getParentWriter + * @expectedException Exception + * @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned. + */ + public function testSetGetParentWriterNull() + { + $object = $this->getMockForAbstractClass( + 'PHPWord_Writer_Word2007_WriterPart' + ); + $object->getParentWriter(); + } +} diff --git a/Tests/PHPWord/Writer/ODTextTest.php b/Tests/PHPWord/Writer/ODTextTest.php index ef92d249..7cc49fba 100644 --- a/Tests/PHPWord/Writer/ODTextTest.php +++ b/Tests/PHPWord/Writer/ODTextTest.php @@ -92,19 +92,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase unlink($file); } - /** - * @covers ::save - * @todo Haven't got any method to test this - */ - public function testSavePhpOutput() - { - $phpWord = new PHPWord(); - $section = $phpWord->createSection(); - $section->addText('Test'); - $writer = new PHPWord_Writer_ODText($phpWord); - $writer->save('php://output'); - } - /** * @covers ::save * @expectedException Exception diff --git a/Tests/PHPWord/Writer/RTFTest.php b/Tests/PHPWord/Writer/RTFTest.php index d071def7..8735c7d7 100644 --- a/Tests/PHPWord/Writer/RTFTest.php +++ b/Tests/PHPWord/Writer/RTFTest.php @@ -35,19 +35,6 @@ class RTFTest extends \PHPUnit_Framework_TestCase $object->getPHPWord(); } - /** - * @covers ::save - * @todo Haven't got any method to test this - */ - public function testSavePhpOutput() - { - $phpWord = new PHPWord(); - $section = $phpWord->createSection(); - $section->addText('Test'); - $writer = new PHPWord_Writer_RTF($phpWord); - $writer->save('php://output'); - } - /** * @covers ::save * @expectedException Exception @@ -78,13 +65,15 @@ class RTFTest extends \PHPUnit_Framework_TestCase array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf') ); + $fontStyle = array('name' => 'Verdana', 'size' => 11, 'bold' => true, 'italic' => true, 'color' => 'F29101', 'fgColor' => '123456'); + $paragraphStyle = array('align' => 'center', 'spaceAfter' => 120); $phpWord = new PHPWord(); - $phpWord->addFontStyle('Font', array('size' => 11)); - $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); + $phpWord->addFontStyle('Font', $fontStyle); + $phpWord->addParagraphStyle('Paragraph', $paragraphStyle); $section = $phpWord->createSection(); $section->addText('Test 1', 'Font'); + $section->addText('Test 2', array('name' => 'Tahoma'), 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2', null, 'Paragraph'); $section->addLink('http://test.com'); $section->addTitle('Test', 1); $section->addPageBreak(); diff --git a/Tests/PHPWord/Writer/Word2007/DocumentTest.php b/Tests/PHPWord/Writer/Word2007/DocumentTest.php index fe854fee..5bc11b5a 100644 --- a/Tests/PHPWord/Writer/Word2007/DocumentTest.php +++ b/Tests/PHPWord/Writer/Word2007/DocumentTest.php @@ -84,4 +84,4 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $element = $doc->getElement('/w:document/w:body/w:p[11]/w:r/w:object/o:OLEObject'); $this->assertEquals('Embed', $element->getAttribute('Type')); } -} +} \ No newline at end of file diff --git a/Tests/PHPWord/Writer/Word2007/FooterTest.php b/Tests/PHPWord/Writer/Word2007/FooterTest.php new file mode 100644 index 00000000..1facc622 --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/FooterTest.php @@ -0,0 +1,44 @@ +addText(''); + $container->addPreserveText(''); + $container->addTextBreak(); + $container->createTextRun(); + $container->addTable()->addRow()->addCell()->addText(''); + $container->addImage($imageSrc); + + $writer = new PHPWord_Writer_Word2007(); + $object = new PHPWord_Writer_Word2007_Footer(); + $object->setParentWriter($writer); + $object->writeFooter($container); + $writer->setUseDiskCaching(true); + $xml = simplexml_load_string($object->writeFooter($container)); + + $this->assertInstanceOf('SimpleXMLElement', $xml); + } +} diff --git a/Tests/PHPWord/Writer/Word2007/HeaderTest.php b/Tests/PHPWord/Writer/Word2007/HeaderTest.php new file mode 100644 index 00000000..f4972b7c --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/HeaderTest.php @@ -0,0 +1,46 @@ +addText('Test'); + $container->addPreserveText(''); + $container->addTextBreak(); + $container->createTextRun(); + $container->addTable()->addRow()->addCell()->addText(''); + $container->addImage($imageSrc); + $container->addWatermark($imageSrc); + + $writer = new PHPWord_Writer_Word2007(); + $object = new PHPWord_Writer_Word2007_Header(); + $object->setParentWriter($writer); + $object->writeHeader($container); + $writer->setUseDiskCaching(true); + $xml = simplexml_load_string($object->writeHeader($container)); + + $this->assertInstanceOf('SimpleXMLElement', $xml); + } +} diff --git a/Tests/PHPWord/Writer/Word2007/WriterPartTest.php b/Tests/PHPWord/Writer/Word2007/WriterPartTest.php new file mode 100644 index 00000000..3d983178 --- /dev/null +++ b/Tests/PHPWord/Writer/Word2007/WriterPartTest.php @@ -0,0 +1,45 @@ +getMockForAbstractClass( + 'PHPWord_Writer_Word2007_WriterPart' + ); + $object->setParentWriter(new PHPWord_Writer_Word2007()); + $this->assertEquals( + new PHPWord_Writer_Word2007(), + $object->getParentWriter() + ); + } + + /** + * covers ::getParentWriter + * @expectedException Exception + * @expectedExceptionMessage No parent PHPWord_Writer_IWriter assigned. + */ + public function testSetGetParentWriterNull() + { + $object = $this->getMockForAbstractClass( + 'PHPWord_Writer_Word2007_WriterPart' + ); + $object->getParentWriter(); + } +} diff --git a/Tests/PHPWord/Writer/Word2007Test.php b/Tests/PHPWord/Writer/Word2007Test.php index 95abee83..ca1d7d82 100644 --- a/Tests/PHPWord/Writer/Word2007Test.php +++ b/Tests/PHPWord/Writer/Word2007Test.php @@ -67,6 +67,26 @@ class Word2007Test extends \PHPUnit_Framework_TestCase unlink($file); } + /** + * @covers ::save + * @expectedException Exception + * @expectedExceptionMessage PHPWord object unassigned. + */ + public function testSaveException() + { + $writer = new PHPWord_Writer_Word2007(); + $writer->save(); + } + + /** + * @covers ::getWriterPart + */ + public function testGetWriterPartNull() + { + $object = new PHPWord_Writer_Word2007(); + $this->assertNull($object->getWriterPart('foo')); + } + /** * @covers ::checkContentTypes */ @@ -100,13 +120,14 @@ class Word2007Test extends \PHPUnit_Framework_TestCase /** * @covers ::setUseDiskCaching * @covers ::getUseDiskCaching + * @covers ::getDiskCachingDirectory */ public function testSetGetUseDiskCaching() { $object = new PHPWord_Writer_Word2007(); $object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT); - $this->assertTrue($object->getUseDiskCaching()); + $this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory()); } /** diff --git a/Tests/PHPWordTest.php b/Tests/PHPWordTest.php index 15106af6..c08d0885 100644 --- a/Tests/PHPWordTest.php +++ b/Tests/PHPWordTest.php @@ -172,7 +172,7 @@ class PHPWordTest extends \PHPUnit_Framework_TestCase /** * @covers PHPWord::loadTemplate - * @expectedException PHPWord_Exception + * @expectedException Exception */ public function testLoadTemplateException() { diff --git a/Tests/_files/templates/clone-merge.docx b/Tests/_files/templates/clone-merge.docx new file mode 100644 index 00000000..eb944367 Binary files /dev/null and b/Tests/_files/templates/clone-merge.docx differ diff --git a/Tests/_files/templates/clone-row.docx b/Tests/_files/templates/clone-row.docx index eb944367..8bea4f03 100644 Binary files a/Tests/_files/templates/clone-row.docx and b/Tests/_files/templates/clone-row.docx differ diff --git a/Tests/_inc/TestHelperDOCX.php b/Tests/_inc/TestHelperDOCX.php index dec1f077..ba5dcf07 100644 --- a/Tests/_inc/TestHelperDOCX.php +++ b/Tests/_inc/TestHelperDOCX.php @@ -5,11 +5,14 @@ use PHPWord; class TestHelperDOCX { - /** @var string $file */ - static protected $file; + /** + * @var string + */ + protected static $file; /** * @param \PHPWord $PHPWord + * @param string $writer * @return \PHPWord\Tests\XmlDocument */ public static function getDocument(PHPWord $PHPWord, $writer = 'Word2007') @@ -67,4 +70,4 @@ class TestHelperDOCX { return self::$file; } -} +} \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index 79d506c4..23c4c4c2 100755 --- a/changelog.txt +++ b/changelog.txt @@ -22,8 +22,8 @@ * @version ##VERSION##, ##DATE## ************************************************************************************** -Changes in branch for release 0.9.0 : -- QA: (Progi1984) - Documentation +Changes in branch for release 0.8.1 : +- Feature: (bskrtich, gabrielbull) - Added fallback for computers that do not have exif_imagetype Changes in branch for release 0.8.0 : - Bugfix: (gabrielbull) - Fixed bug with cell styling