From 1751ab09eec1de00f20cc64bdf5222b01a0589f0 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 3 Apr 2014 11:34:06 +0700 Subject: [PATCH] Remove unused ZipStreamWrapper.php and cleanup some scripts --- CHANGELOG.md | 2 +- src/PhpWord/Container/Container.php | 24 ++- src/PhpWord/Container/Section.php | 2 + src/PhpWord/Element/Footnote.php | 2 + src/PhpWord/Element/Table.php | 2 +- src/PhpWord/Footnote.php | 2 + src/PhpWord/IOFactory.php | 8 +- src/PhpWord/Media.php | 1 + src/PhpWord/PhpWord.php | 5 +- src/PhpWord/Reader/Word2007.php | 2 +- src/PhpWord/Shared/ZipArchive.php | 55 +++--- src/PhpWord/Shared/ZipStreamWrapper.php | 181 ------------------ src/PhpWord/Writer/ODText.php | 2 +- src/PhpWord/Writer/ODText/Content.php | 66 ++----- src/PhpWord/Writer/RTF.php | 36 ++-- src/PhpWord/Writer/Word2007.php | 40 ++-- src/PhpWord/Writer/Word2007/Base.php | 3 +- src/PhpWord/Writer/Word2007/ContentTypes.php | 10 +- src/PhpWord/Writer/Word2007/DocProps.php | 2 +- src/PhpWord/Writer/Word2007/Document.php | 2 +- tests/PhpWord/Tests/Container/FooterTest.php | 7 +- tests/PhpWord/Tests/Container/HeaderTest.php | 7 +- tests/PhpWord/Tests/Container/SectionTest.php | 3 +- tests/PhpWord/Tests/Element/CellTest.php | 7 +- 24 files changed, 135 insertions(+), 336 deletions(-) delete mode 100644 src/PhpWord/Shared/ZipStreamWrapper.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f1430f0a..26c9f071 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers - Writer: Refactor writer classes and make a new Writer abstract class - @ivanlanin GH-160 - Reader: Rename AbstractReader > Reader - @ivanlanin - General: Refactor folders: Element, Container, and Exception - @ivanlanin GH-187 -- General: Remove legacy HashTable and all related properties/methods - @ivanlanin GH-187 +- General: Remove legacy HashTable and ZipStreamWrapper and all related properties/methods - @ivanlanin GH-187 - Container: Create new Container abstract class - @ivanlanin GH-187 - Element: Create new Element abstract class - @ivanlanin GH-187 diff --git a/src/PhpWord/Container/Container.php b/src/PhpWord/Container/Container.php index 95fa186f..0209b4c5 100644 --- a/src/PhpWord/Container/Container.php +++ b/src/PhpWord/Container/Container.php @@ -312,7 +312,9 @@ abstract class Container extends Element $rID = Media::addMediaElement('footnote', 'image', $src, $image); break; } - $image->setRelationId($rID); + if (is_int($rID)) { + $image->setRelationId($rID); + } $this->elements[] = $image; return $image; } else { @@ -366,7 +368,9 @@ abstract class Container extends Element $objectId = $data[1]; $object->setRelationId($rID); $object->setObjectId($objectId); - $object->setImageRelationId($rIDimg); + if (is_int($rIDimg)) { + $object->setImageRelationId($rIDimg); + } $this->elements[] = $object; return $object; } else { @@ -460,6 +464,7 @@ abstract class Container extends Element * @param string $src * @param mixed $style * @deprecated 0.9.0 + * @codeCoverageIgnore */ public function addMemoryImage($src, $style = null) { @@ -471,6 +476,7 @@ abstract class Container extends Element * * @param mixed $paragraphStyle * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function createTextRun($paragraphStyle = null) { @@ -482,6 +488,7 @@ abstract class Container extends Element * * @param mixed $paragraphStyle * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function createFootnote($paragraphStyle = null) { @@ -496,11 +503,12 @@ abstract class Container extends Element */ private function checkValidity($method) { + // Empty array means the element can be accepted by all containers $validContainers = array( - 'text' => 'all', - 'link' => 'all', - 'textbreak' => 'all', - 'image' => 'all', + 'text' => array(), + 'link' => array(), + 'textbreak' => array(), + 'image' => array(), 'textrun' => array('section', 'header', 'footer', 'cell'), 'listitem' => array('section', 'header', 'footer', 'cell'), 'checkbox' => array('section', 'header', 'footer', 'cell'), @@ -511,6 +519,8 @@ abstract class Container extends Element 'relationid' => array('header', 'footer', 'footnote'), 'title' => array('section'), ); + // Special condition, e.g. preservetext can only exists in cell when + // the cell is located in header or footer $validContainerInContainers = array( 'preservetext' => array(array('cell'), array('header', 'footer')), 'object' => array(array('cell', 'textrun'), array('section')), @@ -519,7 +529,7 @@ abstract class Container extends Element // Check if a method is valid for current container if (array_key_exists($method, $validContainers)) { - if (is_array($validContainers[$method])) { + if (!empty($validContainers[$method])) { if (!in_array($this->container, $validContainers[$method])) { throw new \BadMethodCallException(); } diff --git a/src/PhpWord/Container/Section.php b/src/PhpWord/Container/Section.php index dfbc9a72..5e39ee06 100644 --- a/src/PhpWord/Container/Section.php +++ b/src/PhpWord/Container/Section.php @@ -169,6 +169,7 @@ class Section extends Container * Create header * * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function createHeader() { @@ -179,6 +180,7 @@ class Section extends Container * Create footer * * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function createFooter() { diff --git a/src/PhpWord/Element/Footnote.php b/src/PhpWord/Element/Footnote.php index 67cd5d9a..ff0c9960 100644 --- a/src/PhpWord/Element/Footnote.php +++ b/src/PhpWord/Element/Footnote.php @@ -50,6 +50,7 @@ class Footnote extends Container * * @return int * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function getReferenceId() { @@ -61,6 +62,7 @@ class Footnote extends Container * * @param int $refId * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function setReferenceId($refId) { diff --git a/src/PhpWord/Element/Table.php b/src/PhpWord/Element/Table.php index 72362c07..fb50caf2 100644 --- a/src/PhpWord/Element/Table.php +++ b/src/PhpWord/Element/Table.php @@ -41,7 +41,7 @@ class Table extends Element /** * Table holder count * - * @var array + * @var int */ private $docPartId; diff --git a/src/PhpWord/Footnote.php b/src/PhpWord/Footnote.php index 2ec3d0b3..f656dc3a 100644 --- a/src/PhpWord/Footnote.php +++ b/src/PhpWord/Footnote.php @@ -65,6 +65,7 @@ class Footnote * @param string $linkSrc * @return int Reference ID * @deprecated 0.9.2 + * @codeCoverageIgnore */ public static function addFootnoteLinkElement($linkSrc) { @@ -76,6 +77,7 @@ class Footnote * * @return array * @deprecated 0.9.2 + * @codeCoverageIgnore */ public static function getFootnoteLinkElements() { diff --git a/src/PhpWord/IOFactory.php b/src/PhpWord/IOFactory.php index f99f7a00..eeafb057 100644 --- a/src/PhpWord/IOFactory.php +++ b/src/PhpWord/IOFactory.php @@ -22,9 +22,9 @@ abstract class IOFactory * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param string $name * @return \PhpOffice\PhpWord\Writer\IWriter - * @throws \PhpOffice\PhpWord\Exception\Exception + * @throws Exception */ - public static function createWriter(PhpWord $phpWord, $name) + public static function createWriter(PhpWord $phpWord, $name = 'Word2007') { if ($name !== 'IWriter' && $name !== 'ODText' && $name !== 'RTF' && $name !== 'Word2007') { throw new Exception("\"{$name}\" is not a valid writer."); @@ -39,9 +39,9 @@ abstract class IOFactory * * @param string $name * @return \PhpOffice\PhpWord\Reader\IReader - * @throws \PhpOffice\PhpWord\Exception\Exception + * @throws Exception */ - public static function createReader($name) + public static function createReader($name = 'Word2007') { if ($name !== 'IReader' && $name !== 'Word2007') { throw new Exception("\"{$name}\" is not a valid reader."); diff --git a/src/PhpWord/Media.php b/src/PhpWord/Media.php index 99fd5c21..a026304d 100755 --- a/src/PhpWord/Media.php +++ b/src/PhpWord/Media.php @@ -194,6 +194,7 @@ class Media /** * Get Header Media Elements * + * @param string $prefix header|footer * @return array */ public static function getHeaderMediaElements($prefix = 'header') diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index 12143a3f..420b9d7e 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -95,7 +95,7 @@ class PhpWord /** * Create new section * - * @param \PhpOffice\PhpWord\Container\Settings $settings + * @param array $settings * @return Section */ public function addSection($settings = null) @@ -243,9 +243,10 @@ class PhpWord /** * Create new section * - * @param \PhpOffice\PhpWord\Container\Settings $settings + * @param array $settings * @return Section * @deprecated 0.9.2 + * @codeCoverageIgnore */ public function createSection($settings = null) { diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 41bfd85f..175d7fd3 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -234,7 +234,7 @@ class Word2007 extends Reader implements IReader $styleName = (string)$elm->name['val']; if ($hasParagraphStyle) { $pStyle = $this->loadParagraphStyle($elm); - if (!$hasFontStyle) { + if (is_array($pStyle) && !$hasFontStyle) { $word->addParagraphStyle($styleName, $pStyle); } } diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index f207385c..7ef0889e 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -36,14 +36,14 @@ class ZipArchive * * @var string */ - private $_tempDir; + private $tempDir; /** * Zip Archive Stream Handle * * @var string */ - private $_zip; + private $zip; /** * Open a new zip archive @@ -53,8 +53,8 @@ class ZipArchive */ public function open($fileName) { - $this->_tempDir = sys_get_temp_dir(); - $this->_zip = new \PclZip($fileName); + $this->tempDir = sys_get_temp_dir(); + $this->zip = new \PclZip($fileName); return true; } @@ -83,13 +83,13 @@ class ZipArchive // To Rename the file while adding it to the zip we // need to create a temp file with the correct name if ($filenameParts['basename'] != $localnameParts['basename']) { - $temppath = $this->_tempDir . '/' . $localnameParts['basename']; + $temppath = $this->tempDir . '/' . $localnameParts['basename']; copy($filename, $temppath); $filename = $temppath; $filenameParts = pathinfo($temppath); } - $res = $this->_zip->add( + $res = $this->zip->add( $filename, PCLZIP_OPT_REMOVE_PATH, $filenameParts['dirname'], @@ -98,8 +98,7 @@ class ZipArchive ); if ($res == 0) { - throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true)); - return false; + throw new Exception("Error zipping files : " . $this->zip->errorInfo(true)); } return true; @@ -116,25 +115,24 @@ class ZipArchive $filenameParts = pathinfo($localname); // Write $contents to a temp file - $handle = fopen($this->_tempDir . '/' . $filenameParts["basename"], "wb"); + $handle = fopen($this->tempDir . '/' . $filenameParts["basename"], "wb"); fwrite($handle, $contents); fclose($handle); // Add temp file to zip - $res = $this->_zip->add( - $this->_tempDir . '/' . $filenameParts["basename"], + $res = $this->zip->add( + $this->tempDir . '/' . $filenameParts["basename"], PCLZIP_OPT_REMOVE_PATH, - $this->_tempDir, + $this->tempDir, PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"] ); if ($res == 0) { - throw new Exception("Error zipping files : " . $this->_zip->errorInfo(true)); - return false; + throw new Exception("Error zipping files : " . $this->zip->errorInfo(true)); } // Remove temp file - unlink($this->_tempDir . '/' . $filenameParts["basename"]); + unlink($this->tempDir . '/' . $filenameParts["basename"]); return true; } @@ -147,18 +145,18 @@ class ZipArchive */ public function locateName($fileName) { - $list = $this->_zip->listContent(); + $list = $this->zip->listContent(); $listCount = count($list); - $list_index = -1; + $listIndex = -1; for ($i = 0; $i < $listCount; ++$i) { if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { - $list_index = $i; + $listIndex = $i; break; } } - return ($list_index > -1); + return ($listIndex > -1); } /** @@ -169,31 +167,30 @@ class ZipArchive */ public function getFromName($fileName) { - $list = $this->_zip->listContent(); + $list = $this->zip->listContent(); $listCount = count($list); - $list_index = -1; + $listIndex = -1; for ($i = 0; $i < $listCount; ++$i) { if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { - $list_index = $i; + $listIndex = $i; break; } } - $extracted = ""; - if ($list_index != -1) { - $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING); + if ($listIndex != -1) { + $extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING); } else { - $filename = substr($fileName, 1); - $list_index = -1; + $fileName = substr($fileName, 1); + $listIndex = -1; for ($i = 0; $i < $listCount; ++$i) { if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { - $list_index = $i; + $listIndex = $i; break; } } - $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING); + $extracted = $this->zip->extractByIndex($listIndex, PCLZIP_OPT_EXTRACT_AS_STRING); } if ((is_array($extracted)) && ($extracted != 0)) { $contents = $extracted[0]["content"]; diff --git a/src/PhpWord/Shared/ZipStreamWrapper.php b/src/PhpWord/Shared/ZipStreamWrapper.php deleted file mode 100644 index 23b69d84..00000000 --- a/src/PhpWord/Shared/ZipStreamWrapper.php +++ /dev/null @@ -1,181 +0,0 @@ -_archive = new $zipClass(); - $this->_archive->open($url['host']); - - $this->_fileNameInArchive = $url['fragment']; - $this->_position = 0; - $this->_data = $this->_archive->getFromName($this->_fileNameInArchive); - - return true; - } - - /** - * Stat stream - */ - public function streamStat() - { - return $this->_archive->statName($this->_fileNameInArchive); - } - - /** - * Read stream - * - * @param int $count - */ - public function streamRead($count) - { - $ret = substr($this->_data, $this->_position, $count); - $this->_position += strlen($ret); - return $ret; - } - - /** - * Tell stream - */ - public function streamTell() - { - return $this->_position; - } - - /** - * EOF stream - */ - public function streamEof() - { - return $this->_position >= strlen($this->_data); - } - - /** - * Seek stream - * - * @param int $offset - * @param mixed $whence - */ - public function streamSeek($offset, $whence) - { - switch ($whence) { - case \SEEK_SET: - if ($offset < strlen($this->_data) && $offset >= 0) { - $this->_position = $offset; - return true; - } else { - return false; - } - break; - - case \SEEK_CUR: - if ($offset >= 0) { - $this->_position += $offset; - return true; - } else { - return false; - } - break; - - case \SEEK_END: - if (strlen($this->_data) + $offset >= 0) { - $this->_position = strlen($this->_data) + $offset; - return true; - } else { - return false; - } - break; - - default: - return false; - } - } -} diff --git a/src/PhpWord/Writer/ODText.php b/src/PhpWord/Writer/ODText.php index 04ec0bec..10e90dd3 100755 --- a/src/PhpWord/Writer/ODText.php +++ b/src/PhpWord/Writer/ODText.php @@ -23,9 +23,9 @@ use PhpOffice\PhpWord\Writer\ODText\Styles; */ class ODText extends Writer implements IWriter { - /** * Create new ODText writer + * * @param PhpWord $phpWord */ public function __construct(PhpWord $phpWord = null) diff --git a/src/PhpWord/Writer/ODText/Content.php b/src/PhpWord/Writer/ODText/Content.php index ccbdcfce..2a96e103 100644 --- a/src/PhpWord/Writer/ODText/Content.php +++ b/src/PhpWord/Writer/ODText/Content.php @@ -82,18 +82,18 @@ class Content extends WriterPart $xmlWriter->writeAttribute('office:version', '1.2'); // We firstly search all fonts used - $_sections = $phpWord->getSections(); - $countSections = count($_sections); + $sections = $phpWord->getSections(); + $countSections = count($sections); if ($countSections > 0) { $pSection = 0; $numPStyles = 0; $numFStyles = 0; - foreach ($_sections as $section) { + foreach ($sections as $section) { $pSection++; - $_elements = $section->getElements(); + $elements = $section->getElements(); - foreach ($_elements as $element) { + foreach ($elements as $element) { if ($element instanceof Text) { $fStyle = $element->getFontStyle(); $pStyle = $element->getParagraphStyle(); @@ -232,17 +232,13 @@ class Content extends WriterPart $xmlWriter->endElement(); $xmlWriter->endElement(); - $_sections = $phpWord->getSections(); - $countSections = count($_sections); - $pSection = 0; - + $sections = $phpWord->getSections(); + $countSections = count($sections); if ($countSections > 0) { - foreach ($_sections as $section) { - $pSection++; + foreach ($sections as $section) { + $elements = $section->getElements(); - $_elements = $section->getElements(); - - foreach ($_elements as $element) { + foreach ($elements as $element) { if ($element instanceof Text) { $this->writeText($xmlWriter, $element); } elseif ($element instanceof TextRun) { @@ -269,12 +265,6 @@ class Content extends WriterPart $this->writeUnsupportedElement($xmlWriter, 'Element'); } } - - if ($pSection == $countSections) { - $this->writeEndSection($xmlWriter, $section); - } else { - $this->writeSection($xmlWriter, $section); - } } } $xmlWriter->endElement(); @@ -311,19 +301,21 @@ class Content extends WriterPart if (empty($styleFont)) { if (empty($styleParagraph)) { $xmlWriter->writeAttribute('text:style-name', 'P1'); - } else { - $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } elseif (is_string($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', $styleParagraph); } $xmlWriter->writeRaw($text->getText()); } else { if (empty($styleParagraph)) { $xmlWriter->writeAttribute('text:style-name', 'Standard'); - } else { - $xmlWriter->writeAttribute('text:style-name', $text->getParagraphStyle()); + } elseif (is_string($styleParagraph)) { + $xmlWriter->writeAttribute('text:style-name', $styleParagraph); } // text:span $xmlWriter->startElement('text:span'); - $xmlWriter->writeAttribute('text:style-name', $styleFont); + if (is_string($styleFont)) { + $xmlWriter->writeAttribute('text:style-name', $styleFont); + } $xmlWriter->writeRaw($text->getText()); $xmlWriter->endElement(); } @@ -359,35 +351,13 @@ class Content extends WriterPart * * @param XMLWriter $xmlWriter */ - protected function writeTextBreak(XMLWriter $xmlWriter = null) + protected function writeTextBreak(XMLWriter $xmlWriter) { $xmlWriter->startElement('text:p'); $xmlWriter->writeAttribute('text:style-name', 'Standard'); $xmlWriter->endElement(); } - // @codeCoverageIgnoreStart - /** - * Write end section - * - * @param XMLWriter $xmlWriter - * @param Section $section - */ - private function writeEndSection(XMLWriter $xmlWriter = null, Section $section = null) - { - } - - /** - * Write section - * - * @param XMLWriter $xmlWriter - * @param Section $section - */ - private function writeSection(XMLWriter $xmlWriter = null, Section $section = null) - { - } - // @codeCoverageIgnoreEnd - /** * Write unsupported element * diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index 6d693f17..a990575c 100755 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -170,16 +170,16 @@ class RTF extends Writer implements IWriter } // Search all fonts used - $_sections = $phpWord->getSections(); - $countSections = count($_sections); + $sections = $phpWord->getSections(); + $countSections = count($sections); if ($countSections > 0) { $pSection = 0; - foreach ($_sections as $section) { + foreach ($sections as $section) { $pSection++; - $_elements = $section->getElements(); + $elements = $section->getElements(); - foreach ($_elements as $element) { + foreach ($elements as $element) { if ($element instanceof Text) { $fStyle = $element->getFontStyle(); @@ -227,16 +227,16 @@ class RTF extends Writer implements IWriter } // Search all fonts used - $_sections = $phpWord->getSections(); - $countSections = count($_sections); + $sections = $phpWord->getSections(); + $countSections = count($sections); if ($countSections > 0) { $pSection = 0; - foreach ($_sections as $section) { + foreach ($sections as $section) { $pSection++; - $_elements = $section->getElements(); + $elements = $section->getElements(); - foreach ($_elements as $element) { + foreach ($elements as $element) { if ($element instanceof Text) { $fStyle = $element->getFontStyle(); @@ -266,15 +266,15 @@ class RTF extends Writer implements IWriter $phpWord = $this->phpWord; $sRTFBody = ''; - $_sections = $phpWord->getSections(); - $countSections = count($_sections); + $sections = $phpWord->getSections(); + $countSections = count($sections); $pSection = 0; if ($countSections > 0) { - foreach ($_sections as $section) { + foreach ($sections as $section) { $pSection++; - $_elements = $section->getElements(); - foreach ($_elements as $element) { + $elements = $section->getElements(); + foreach ($elements as $element) { if ($element instanceof Text) { $sRTFBody .= $this->getDataContentText($element); } elseif ($element instanceof TextBreak) { @@ -317,14 +317,12 @@ class RTF extends Writer implements IWriter $sRTFText = ''; $styleFont = $text->getFontStyle(); - $SfIsObject = ($styleFont instanceof Font) ? true : false; - if (!$SfIsObject) { + if (is_string($styleFont)) { $styleFont = Style::getStyle($styleFont); } $styleParagraph = $text->getParagraphStyle(); - $SpIsObject = ($styleParagraph instanceof Paragraph) ? true : false; - if (!$SpIsObject) { + if (is_string($styleParagraph)) { $styleParagraph = Style::getStyle($styleParagraph); } diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index 298b93cc..f86f30ac 100755 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -104,8 +104,8 @@ class Word2007 extends Writer implements IWriter // Add section elements $sectionElements = array(); - $_secElements = Media::getSectionMediaElements(); - foreach ($_secElements as $element) { // loop through section media elements + $secElements = Media::getSectionMediaElements(); + foreach ($secElements as $element) { // loop through section media elements if ($element['type'] != 'hyperlink') { $this->addFileToPackage($objZip, $element); } @@ -145,33 +145,33 @@ class Word2007 extends Writer implements IWriter } // Process header/footer xml files - $_cHdrs = 0; - $_cFtrs = 0; + $cHdrs = 0; + $cFtrs = 0; $rID = Media::countSectionMediaElements() + 6; - $_sections = $this->phpWord->getSections(); + $sections = $this->phpWord->getSections(); $footers = array(); - foreach ($_sections as $section) { - $_headers = $section->getHeaders(); - foreach ($_headers as $index => &$_header) { - $_cHdrs++; - $_header->setRelationId(++$rID); - $hdrFile = "header{$_cHdrs}.xml"; + foreach ($sections as $section) { + $headers = $section->getHeaders(); + foreach ($headers as $index => &$header) { + $cHdrs++; + $header->setRelationId(++$rID); + $hdrFile = "header{$cHdrs}.xml"; $sectionElements[] = array('target' => $hdrFile, 'type' => 'header', 'rID' => $rID); $objZip->addFromString( "word/{$hdrFile}", - $this->getWriterPart('header')->writeHeader($_header) + $this->getWriterPart('header')->writeHeader($header) ); } - $_footer = $section->getFooter(); - $footers[++$_cFtrs] = $_footer; - if (!is_null($_footer)) { - $_footer->setRelationId(++$rID); - $_footerCount = $_footer->getSectionId(); - $ftrFile = "footer{$_footerCount}.xml"; + $footer = $section->getFooter(); + $footers[++$cFtrs] = $footer; + if (!is_null($footer)) { + $footer->setRelationId(++$rID); + $footerCount = $footer->getSectionId(); + $ftrFile = "footer{$footerCount}.xml"; $sectionElements[] = array('target' => $ftrFile, 'type' => 'footer', 'rID' => $rID); $objZip->addFromString( "word/{$ftrFile}", - $this->getWriterPart('footer')->writeFooter($_footer) + $this->getWriterPart('footer')->writeFooter($footer) ); } } @@ -210,7 +210,7 @@ class Word2007 extends Writer implements IWriter $this->getWriterPart('contenttypes')->writeContentTypes( $this->imageTypes, $this->objectTypes, - $_cHdrs, + $cHdrs, $footers ) ); diff --git a/src/PhpWord/Writer/Word2007/Base.php b/src/PhpWord/Writer/Word2007/Base.php index 6220b1f6..50bd6425 100644 --- a/src/PhpWord/Writer/Word2007/Base.php +++ b/src/PhpWord/Writer/Word2007/Base.php @@ -238,6 +238,7 @@ class Base extends WriterPart * * @param XMLWriter $xmlWriter * @param TextBreak $element + * @param boolean $withoutP */ protected function writeTextBreak(XMLWriter $xmlWriter, TextBreak $element = null, $withoutP = false) { @@ -1073,7 +1074,7 @@ class Base extends WriterPart * Write media rels (image, embeddings, hyperlink) * * @param XMLWriter $xmlWriter - * @param array mediaRels + * @param array $mediaRels */ protected function writeMediaRels(XMLWriter $xmlWriter, $mediaRels) { diff --git a/src/PhpWord/Writer/Word2007/ContentTypes.php b/src/PhpWord/Writer/Word2007/ContentTypes.php index 86689823..98bf4e08 100755 --- a/src/PhpWord/Writer/Word2007/ContentTypes.php +++ b/src/PhpWord/Writer/Word2007/ContentTypes.php @@ -21,10 +21,10 @@ class ContentTypes extends WriterPart * Write [Content_Types].xml * @param array $imageTypes * @param array $objectTypes - * @param int $_cHdrs + * @param int $cHdrs * @param array $footers */ - public function writeContentTypes($imageTypes, $objectTypes, $_cHdrs, $footers) + public function writeContentTypes($imageTypes, $objectTypes, $cHdrs, $footers) { // Create XML writer $xmlWriter = $this->getXmlWriter(); @@ -133,7 +133,7 @@ class ContentTypes extends WriterPart 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' ); - for ($i = 1; $i <= $_cHdrs; $i++) { + for ($i = 1; $i <= $cHdrs; $i++) { $this->writeOverrideContentType( $xmlWriter, '/word/header' . $i . '.xml', @@ -165,7 +165,7 @@ class ContentTypes extends WriterPart * @param string $pContentType Content type * @throws Exception */ - private function writeDefaultContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') + private function writeDefaultContentType(XMLWriter $xmlWriter, $pPartname = '', $pContentType = '') { if ($pPartname != '' && $pContentType != '') { // Write content type @@ -186,7 +186,7 @@ class ContentTypes extends WriterPart * @param string $pContentType Content type * @throws Exception */ - private function writeOverrideContentType(XMLWriter $xmlWriter = null, $pPartname = '', $pContentType = '') + private function writeOverrideContentType(XMLWriter $xmlWriter, $pPartname = '', $pContentType = '') { if ($pPartname != '' && $pContentType != '') { // Write content type diff --git a/src/PhpWord/Writer/Word2007/DocProps.php b/src/PhpWord/Writer/Word2007/DocProps.php index 46a74688..ceb5db04 100644 --- a/src/PhpWord/Writer/Word2007/DocProps.php +++ b/src/PhpWord/Writer/Word2007/DocProps.php @@ -111,7 +111,7 @@ class DocProps extends WriterPart * * @param PhpWord $phpWord */ - public function writeDocPropsCore(PhpWord $phpWord = null) + public function writeDocPropsCore(PhpWord $phpWord) { // Create XML writer $xmlWriter = $this->getXmlWriter(); diff --git a/src/PhpWord/Writer/Word2007/Document.php b/src/PhpWord/Writer/Word2007/Document.php index 3c0d6483..8bf46a0b 100644 --- a/src/PhpWord/Writer/Word2007/Document.php +++ b/src/PhpWord/Writer/Word2007/Document.php @@ -84,7 +84,7 @@ class Document extends Base { $xmlWriter->startElement('w:p'); $xmlWriter->startElement('w:pPr'); - $this->writeEndSection($xmlWriter, $section, 3); + $this->writeEndSection($xmlWriter, $section); $xmlWriter->endElement(); $xmlWriter->endElement(); } diff --git a/tests/PhpWord/Tests/Container/FooterTest.php b/tests/PhpWord/Tests/Container/FooterTest.php index ba712903..bcbf45a9 100644 --- a/tests/PhpWord/Tests/Container/FooterTest.php +++ b/tests/PhpWord/Tests/Container/FooterTest.php @@ -98,11 +98,10 @@ class FooterTest extends \PHPUnit_Framework_TestCase { $src = __DIR__ . "/../_files/images/earth.jpg"; $oFooter = new Footer(1); - $element1 = $oFooter->addImage($src); - $element2 = $oFooter->addMemoryImage($src); // @deprecated + $element = $oFooter->addImage($src); - $this->assertCount(2, $oFooter->getElements()); - $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1); + $this->assertCount(1, $oFooter->getElements()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); } /** diff --git a/tests/PhpWord/Tests/Container/HeaderTest.php b/tests/PhpWord/Tests/Container/HeaderTest.php index dab67048..d7425bdc 100644 --- a/tests/PhpWord/Tests/Container/HeaderTest.php +++ b/tests/PhpWord/Tests/Container/HeaderTest.php @@ -107,11 +107,10 @@ class HeaderTest extends \PHPUnit_Framework_TestCase { $src = __DIR__ . "/../_files/images/earth.jpg"; $oHeader = new Header(1); - $element1 = $oHeader->addImage($src); - $element2 = $oHeader->addMemoryImage($src); // @deprecated + $element = $oHeader->addImage($src); - $this->assertCount(2, $oHeader->getElements()); - $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1); + $this->assertCount(1, $oHeader->getElements()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); } /** diff --git a/tests/PhpWord/Tests/Container/SectionTest.php b/tests/PhpWord/Tests/Container/SectionTest.php index a289df49..268f66e8 100644 --- a/tests/PhpWord/Tests/Container/SectionTest.php +++ b/tests/PhpWord/Tests/Container/SectionTest.php @@ -84,7 +84,6 @@ class SectionTest extends \PHPUnit_Framework_TestCase $section->addListItem(utf8_decode('ä')); $section->addObject($objectSource); $section->addImage($imageSource); - $section->addMemoryImage($imageUrl); $section->addTitle(utf8_decode('ä'), 1); $section->addTextRun(); $section->addFootnote(); @@ -93,7 +92,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase $elementCollection = $section->getElements(); $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', - 'Table', 'ListItem', 'Object', 'Image', 'Image', + 'Table', 'ListItem', 'Object', 'Image', 'Title', 'TextRun', 'Footnote', 'CheckBox'); $i = 0; foreach ($elementTypes as $elementType) { diff --git a/tests/PhpWord/Tests/Element/CellTest.php b/tests/PhpWord/Tests/Element/CellTest.php index a3507e3f..3a2c3342 100644 --- a/tests/PhpWord/Tests/Element/CellTest.php +++ b/tests/PhpWord/Tests/Element/CellTest.php @@ -123,11 +123,10 @@ class CellTest extends \PHPUnit_Framework_TestCase { $src = __DIR__ . "/../_files/images/earth.jpg"; $oCell = new Cell('section', 1); - $element1 = $oCell->addImage($src); - $element2 = $oCell->addMemoryImage($src); // @deprecated + $element = $oCell->addImage($src); - $this->assertCount(2, $oCell->getElements()); - $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element1); + $this->assertCount(1, $oCell->getElements()); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element); } /**