diff --git a/src/PhpWord/Reader/AbstractReader.php b/src/PhpWord/Reader/AbstractReader.php index 73d18666..a243c5d2 100644 --- a/src/PhpWord/Reader/AbstractReader.php +++ b/src/PhpWord/Reader/AbstractReader.php @@ -54,47 +54,47 @@ abstract class AbstractReader implements ReaderInterface /** * Set read data only * - * @param bool $pValue + * @param bool $value * @return self */ - public function setReadDataOnly($pValue = true) + public function setReadDataOnly($value = true) { - $this->readDataOnly = $pValue; + $this->readDataOnly = $value; return $this; } /** * Open file for reading * - * @param string $pFilename + * @param string $filename * @return resource * @throws \PhpOffice\PhpWord\Exception\Exception */ - protected function openFile($pFilename) + protected function openFile($filename) { // Check if file exists - if (!file_exists($pFilename) || !is_readable($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + if (!file_exists($filename) || !is_readable($filename)) { + throw new Exception("Could not open " . $filename . " for reading! File does not exist."); } // Open file - $this->fileHandle = fopen($pFilename, 'r'); + $this->fileHandle = fopen($filename, 'r'); if ($this->fileHandle === false) { - throw new Exception("Could not open file " . $pFilename . " for reading."); + throw new Exception("Could not open file " . $filename . " for reading."); } } /** * Can the current ReaderInterface read the file? * - * @param string $pFilename + * @param string $filename * @return bool */ - public function canRead($pFilename) + public function canRead($filename) { // Check if file exists try { - $this->openFile($pFilename); + $this->openFile($filename); } catch (Exception $e) { return false; } diff --git a/src/PhpWord/Reader/ODText/AbstractPart.php b/src/PhpWord/Reader/ODText/AbstractPart.php index 44884922..7a91e12d 100644 --- a/src/PhpWord/Reader/ODText/AbstractPart.php +++ b/src/PhpWord/Reader/ODText/AbstractPart.php @@ -18,11 +18,12 @@ namespace PhpOffice\PhpWord\Reader\ODText; use PhpOffice\PhpWord\Shared\XMLReader; +use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart; /** * Abstract part reader */ -abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart +abstract class AbstractPart extends Word2007AbstractPart { /** * Read w:r (override) diff --git a/src/PhpWord/Reader/ReaderInterface.php b/src/PhpWord/Reader/ReaderInterface.php index f207aa6f..df663197 100644 --- a/src/PhpWord/Reader/ReaderInterface.php +++ b/src/PhpWord/Reader/ReaderInterface.php @@ -25,15 +25,15 @@ interface ReaderInterface /** * Can the current ReaderInterface read the file? * - * @param string $pFilename + * @param string $filename * @return boolean */ - public function canRead($pFilename); + public function canRead($filename); /** * Loads PhpWord from file * - * @param string $pFilename + * @param string $filename */ - public function load($pFilename); + public function load($filename); } diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php index f56a4789..5440f512 100644 --- a/src/PhpWord/Style/Font.php +++ b/src/PhpWord/Style/Font.php @@ -633,7 +633,7 @@ class Font extends AbstractStyle * Set $property value and set $pairProperty = false when $value = true * * @param bool $property - * @param bool $pair + * @param bool $pairProperty * @param bool $value * @return self */ diff --git a/src/PhpWord/Style/Table.php b/src/PhpWord/Style/Table.php index 32821793..90e8282f 100644 --- a/src/PhpWord/Style/Table.php +++ b/src/PhpWord/Style/Table.php @@ -29,12 +29,19 @@ class Table extends Border const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit) const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip) + /** + * Is this a first row style? + * + * @var bool + */ + private $isFirstRow = false; + /** * Style for first row * * @var \PhpOffice\PhpWord\Style\Table */ - private $firstRow; + private $firstRowStyle; /** * Cell margin top @@ -126,17 +133,18 @@ class Table extends Border // Clone first row from table style, but with certain properties disabled if ($firstRowStyle !== null && is_array($firstRowStyle)) { - $this->firstRow = clone $this; - unset($this->firstRow->firstRow); - unset($this->firstRow->borderInsideHSize); - unset($this->firstRow->borderInsideHColor); - unset($this->firstRow->borderInsideVSize); - unset($this->firstRow->borderInsideVColor); - unset($this->firstRow->cellMarginTop); - unset($this->firstRow->cellMarginLeft); - unset($this->firstRow->cellMarginRight); - unset($this->firstRow->cellMarginBottom); - $this->firstRow->setStyleByArray($firstRowStyle); + $this->firstRowStyle = clone $this; + $this->firstRowStyle->isFirstRow = true; + unset($this->firstRowStyle->firstRowStyle); + unset($this->firstRowStyle->borderInsideHSize); + unset($this->firstRowStyle->borderInsideHColor); + unset($this->firstRowStyle->borderInsideVSize); + unset($this->firstRowStyle->borderInsideVColor); + unset($this->firstRowStyle->cellMarginTop); + unset($this->firstRowStyle->cellMarginLeft); + unset($this->firstRowStyle->cellMarginRight); + unset($this->firstRowStyle->cellMarginBottom); + $this->firstRowStyle->setStyleByArray($firstRowStyle); } if ($tableStyle !== null && is_array($tableStyle)) { @@ -145,13 +153,13 @@ class Table extends Border } /** - * Get First Row Style + * Set first row * * @return \PhpOffice\PhpWord\Style\Table */ public function getFirstRow() { - return $this->firstRow; + return $this->firstRowStyle; } /** @@ -556,7 +564,7 @@ class Table extends Border } /** - * Get table style only property by checking if firstRow is set + * Get table style only property by checking if it's a firstRow * * This is necessary since firstRow style is cloned from table style but * without certain properties activated, e.g. margins @@ -566,7 +574,7 @@ class Table extends Border */ private function getTableOnlyProperty($property) { - if (isset($this->firstRow)) { + if ($this->isFirstRow === false) { return $this->$property; } @@ -574,7 +582,7 @@ class Table extends Border } /** - * Set table style only property by checking if firstRow is set + * Set table style only property by checking if it's a firstRow * * This is necessary since firstRow style is cloned from table style but * without certain properties activated, e.g. margins @@ -586,8 +594,8 @@ class Table extends Border */ private function setTableOnlyProperty($property, $value, $isNumeric = true) { - if (isset($this->firstRow)) { - if ($isNumeric) { + if ($this->isFirstRow === false) { + if ($isNumeric === true) { $this->$property = $this->setNumericVal($value, $this->$property); } else { $this->$property = $value; diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index bc1c1bf9..628dd045 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -335,7 +335,7 @@ abstract class AbstractWriter implements WriterInterface $source = substr($source, 6); list($zipFilename, $imageFilename) = explode('#', $source); - $zipClass = \PhpOffice\PhpWord\Settings::getZipClass(); + $zipClass = Settings::getZipClass(); $zip = new $zipClass(); if ($zip->open($zipFilename) !== false) { if ($zip->locateName($imageFilename)) { diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index 6c1a534f..db1723aa 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -62,14 +62,10 @@ class HTML extends AbstractWriter implements WriterInterface * Save PhpWord to file * * @param string $filename - * @throws Exception + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { - if (is_null($this->phpWord)) { - throw new Exception('PhpWord object unassigned.'); - } - $this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/'); $hFile = fopen($filename, 'w'); if ($hFile !== false) { @@ -111,7 +107,8 @@ class HTML extends AbstractWriter implements WriterInterface */ private function writeHead() { - $properties = $this->getPhpWord()->getDocumentProperties(); + $phpWord = $this->getPhpWord(); + $properties = $phpWord->getDocumentProperties(); $propertiesMapping = array( 'creator' => 'author', 'title' => '', @@ -171,13 +168,14 @@ class HTML extends AbstractWriter implements WriterInterface */ private function writeStyles() { + $phpWord = $this->getPhpWord(); $css = '