From 59a938c4dd324109d68ec0083267adb49bb13730 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 5 Nov 2012 22:42:58 +0000 Subject: [PATCH] Refactor common writer settings/methods into an abstract writer class --- Classes/PHPExcel/Writer/Abstract.php | 149 +++++++++++++++++++++++++ Classes/PHPExcel/Writer/CSV.php | 32 +----- Classes/PHPExcel/Writer/Excel2007.php | 116 +------------------ Classes/PHPExcel/Writer/Excel5.php | 27 +---- Classes/PHPExcel/Writer/HTML.php | 66 +---------- Classes/PHPExcel/Writer/PDF.php | 10 +- Classes/PHPExcel/Writer/PDF/Core.php | 12 +- Classes/PHPExcel/Writer/PDF/DomPDF.php | 4 +- Classes/PHPExcel/Writer/PDF/mPDF.php | 4 +- Classes/PHPExcel/Writer/PDF/tcPDF.php | 4 +- 10 files changed, 176 insertions(+), 248 deletions(-) create mode 100644 Classes/PHPExcel/Writer/Abstract.php diff --git a/Classes/PHPExcel/Writer/Abstract.php b/Classes/PHPExcel/Writer/Abstract.php new file mode 100644 index 00000000..3901e762 --- /dev/null +++ b/Classes/PHPExcel/Writer/Abstract.php @@ -0,0 +1,149 @@ +_includeCharts; + } + + /** + * Set write charts in workbook + * Set to true, to advise the Writer to include any charts that exist in the PHPExcel object. + * Set to false (the default) to ignore charts. + * + * @param boolean $pValue + * @return PHPExcel_Writer_IWriter + */ + public function setIncludeCharts($pValue = FALSE) { + $this->_includeCharts = (boolean) $pValue; + return $this; + } + + /** + * Get Pre-Calculate Formulas + * + * @return boolean + */ + public function getPreCalculateFormulas() { + return $this->_preCalculateFormulas; + } + + /** + * Set Pre-Calculate Formulas + * + * @param boolean $pValue Pre-Calculate Formulas? + * @return PHPExcel_Writer_IWriter + */ + public function setPreCalculateFormulas($pValue = TRUE) { + $this->_preCalculateFormulas = (boolean) $pValue; + return $this; + } + + /** + * Get use disk caching where possible? + * + * @return boolean + */ + public function getUseDiskCaching() { + return $this->_useDiskCaching; + } + + /** + * Set use disk caching where possible? + * + * @param boolean $pValue + * @param string $pDirectory Disk caching directory + * @throws PHPExcel_Writer_Exception Exception when directory does not exist + * @return PHPExcel_Writer_Excel2007 + */ + public function setUseDiskCaching($pValue = FALSE, $pDirectory = NULL) { + $this->_useDiskCaching = $pValue; + + if ($pDirectory !== NULL) { + if (is_dir($pDirectory)) { + $this->_diskCachingDirectory = $pDirectory; + } else { + throw new PHPExcel_Writer_Exception("Directory does not exist: $pDirectory"); + } + } + return $this; + } + + /** + * Get disk caching directory + * + * @return string + */ + public function getDiskCachingDirectory() { + return $this->_diskCachingDirectory; + } +} diff --git a/Classes/PHPExcel/Writer/CSV.php b/Classes/PHPExcel/Writer/CSV.php index be9761f3..2ff5b410 100644 --- a/Classes/PHPExcel/Writer/CSV.php +++ b/Classes/PHPExcel/Writer/CSV.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_CSV * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -30,10 +30,10 @@ * PHPExcel_Writer_CSV * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_CSV * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ -class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter { +class PHPExcel_Writer_CSV extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter { /** * PHPExcel object * @@ -69,13 +69,6 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter { */ private $_sheetIndex = 0; - /** - * Pre-calculate formulas - * - * @var boolean - */ - private $_preCalculateFormulas = true; - /** * Whether to write a BOM (for UTF8). * @@ -317,23 +310,4 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter { } } - /** - * Get Pre-Calculate Formulas - * - * @return boolean - */ - public function getPreCalculateFormulas() { - return $this->_preCalculateFormulas; - } - - /** - * Set Pre-Calculate Formulas - * - * @param boolean $pValue Pre-Calculate Formulas? - * @return PHPExcel_Writer_CSV - */ - public function setPreCalculateFormulas($pValue = true) { - $this->_preCalculateFormulas = $pValue; - return $this; - } } diff --git a/Classes/PHPExcel/Writer/Excel2007.php b/Classes/PHPExcel/Writer/Excel2007.php index e2ec139c..00d041c0 100644 --- a/Classes/PHPExcel/Writer/Excel2007.php +++ b/Classes/PHPExcel/Writer/Excel2007.php @@ -30,26 +30,11 @@ * PHPExcel_Writer_Excel2007 * * @category PHPExcel - * @package PHPExcel_Writer_Excel2007 + * @package PHPExcel_Writer * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ -class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter +class PHPExcel_Writer_Excel2007 extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter { - /** - * Write charts that are defined in the workbook? - * Identifies whether the Writer should write definitions for any charts that exist in the PHPExcel object; - * - * @var boolean - */ - private $_includeCharts = false; - - /** - * Pre-calculate formulas - * - * @var boolean - */ - private $_preCalculateFormulas = true; - /** * Office2003 compatibility * @@ -120,20 +105,6 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter */ private $_drawingHashTable; - /** - * Use disk caching where possible? - * - * @var boolean - */ - private $_useDiskCaching = false; - - /** - * Disk caching directory - * - * @var string - */ - private $_diskCachingDirectory = './'; - /** * Create a new PHPExcel_Writer_Excel2007 * @@ -479,49 +450,6 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter return $this->_drawingHashTable; } - /** - * Write charts in workbook? - * If this is true, then the Writer will write definitions for any charts that exist in the PHPExcel object. - * If false (the default) it will ignore any charts defined in the PHPExcel object. - * - * @return boolean - */ - public function getIncludeCharts() { - return $this->_includeCharts; - } - - /** - * Set write charts in workbook - * Set to true, to advise the Writer to include any charts that exist in the PHPExcel object. - * Set to false (the default) to ignore charts. - * - * @param boolean $pValue - * - * @return PHPExcel_Writer_Excel2007 - */ - public function setIncludeCharts($pValue = false) { - $this->_includeCharts = (boolean) $pValue; - return $this; - } - - /** - * Get Pre-Calculate Formulas - * - * @return boolean - */ - public function getPreCalculateFormulas() { - return $this->_preCalculateFormulas; - } - - /** - * Set Pre-Calculate Formulas - * - * @param boolean $pValue Pre-Calculate Formulas? - */ - public function setPreCalculateFormulas($pValue = true) { - $this->_preCalculateFormulas = $pValue; - } - /** * Get Office2003 compatibility * @@ -532,7 +460,7 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter } /** - * Set Pre-Calculate Formulas + * Set Office2003 compatibility * * @param boolean $pValue Office2003 compatibility? * @return PHPExcel_Writer_Excel2007 @@ -542,42 +470,4 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter return $this; } - /** - * Get use disk caching where possible? - * - * @return boolean - */ - public function getUseDiskCaching() { - return $this->_useDiskCaching; - } - - /** - * Set use disk caching where possible? - * - * @param boolean $pValue - * @param string $pDirectory Disk caching directory - * @throws PHPExcel_Writer_Exception Exception when directory does not exist - * @return PHPExcel_Writer_Excel2007 - */ - public function setUseDiskCaching($pValue = false, $pDirectory = null) { - $this->_useDiskCaching = $pValue; - - if ($pDirectory !== NULL) { - if (is_dir($pDirectory)) { - $this->_diskCachingDirectory = $pDirectory; - } else { - throw new PHPExcel_Writer_Exception("Directory does not exist: $pDirectory"); - } - } - return $this; - } - - /** - * Get disk caching directory - * - * @return string - */ - public function getDiskCachingDirectory() { - return $this->_diskCachingDirectory; - } } diff --git a/Classes/PHPExcel/Writer/Excel5.php b/Classes/PHPExcel/Writer/Excel5.php index 609df7be..07edc201 100644 --- a/Classes/PHPExcel/Writer/Excel5.php +++ b/Classes/PHPExcel/Writer/Excel5.php @@ -33,15 +33,8 @@ * @package PHPExcel_Writer_Excel5 * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ -class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter +class PHPExcel_Writer_Excel5 extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter { - /** - * Pre-calculate formulas - * - * @var boolean - */ - private $_preCalculateFormulas = true; - /** * PHPExcel object * @@ -248,24 +241,6 @@ class PHPExcel_Writer_Excel5 implements PHPExcel_Writer_IWriter return $this; } - /** - * Get Pre-Calculate Formulas - * - * @return boolean - */ - public function getPreCalculateFormulas() { - return $this->_preCalculateFormulas; - } - - /** - * Set Pre-Calculate Formulas - * - * @param boolean $pValue Pre-Calculate Formulas? - */ - public function setPreCalculateFormulas($pValue = true) { - $this->_preCalculateFormulas = $pValue; - } - /** * Build the Worksheet Escher objects * diff --git a/Classes/PHPExcel/Writer/HTML.php b/Classes/PHPExcel/Writer/HTML.php index 14e765d4..0c803c02 100644 --- a/Classes/PHPExcel/Writer/HTML.php +++ b/Classes/PHPExcel/Writer/HTML.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_HTML * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -30,10 +30,10 @@ * PHPExcel_Writer_HTML * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_HTML * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ -class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { +class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter { /** * PHPExcel object * @@ -48,21 +48,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { */ private $_sheetIndex = 0; - /** - * Write charts that are defined in the workbook? - * Identifies whether the Writer should write definitions for any charts that exist in the PHPExcel object; - * - * @var boolean - */ - private $_includeCharts = false; - - /** - * Pre-calculate formulas - * - * @var boolean - */ - private $_preCalculateFormulas = true; - /** * Images root * @@ -1272,26 +1257,6 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { return $string; } - /** - * Get Pre-Calculate Formulas - * - * @return boolean - */ - public function getPreCalculateFormulas() { - return $this->_preCalculateFormulas; - } - - /** - * Set Pre-Calculate Formulas - * - * @param boolean $pValue Pre-Calculate Formulas? - * @return PHPExcel_Writer_HTML - */ - public function setPreCalculateFormulas($pValue = true) { - $this->_preCalculateFormulas = $pValue; - return $this; - } - /** * Get images root * @@ -1473,29 +1438,4 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { $this->_spansAreCalculated = true; } - /** - * Write charts in workbook? - * If this is true, then the Writer will write definitions for any charts that exist in the PHPExcel object. - * If false (the default) it will ignore any charts defined in the PHPExcel object. - * - * @return boolean - */ - public function getIncludeCharts() { - return $this->_includeCharts; - } - - /** - * Set write charts in workbook - * Set to true, to advise the Writer to include any charts that exist in the PHPExcel object. - * Set to false (the default) to ignore charts. - * - * @param boolean $pValue - * - * @return PHPExcel_Writer_Excel2007 - */ - public function setIncludeCharts($pValue = false) { - $this->_includeCharts = (boolean) $pValue; - return $this; - } - } diff --git a/Classes/PHPExcel/Writer/PDF.php b/Classes/PHPExcel/Writer/PDF.php index 60f8803b..e2c9112b 100644 --- a/Classes/PHPExcel/Writer/PDF.php +++ b/Classes/PHPExcel/Writer/PDF.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -30,7 +30,7 @@ * PHPExcel_Writer_PDF * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Writer_PDF @@ -39,7 +39,7 @@ class PHPExcel_Writer_PDF private $_renderer = NULL; /** - * Create a new PHPExcel_Writer_PDF + * Instantiate a new renderer of the configured type within this container class * * @param PHPExcel $phpExcel PHPExcel object * @throws PHPExcel_Writer_Exception Exception when PDF library is not configured @@ -67,11 +67,11 @@ class PHPExcel_Writer_PDF /** - * Magic method to handle direct calls to the renderer library + * Magic method to handle direct calls to the configured PDF renderer wrapper class * * @param string $name Renderer library method name * @param mixed[] $arguments Array of arguments to pass to the renderer method - * @return mixed Returned data from the renderer method + * @return mixed Returned data from the PDF renderer wrapper method */ public function __call($name, $arguments) { diff --git a/Classes/PHPExcel/Writer/PDF/Core.php b/Classes/PHPExcel/Writer/PDF/Core.php index e477ceb6..f9008381 100644 --- a/Classes/PHPExcel/Writer/PDF/Core.php +++ b/Classes/PHPExcel/Writer/PDF/Core.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -30,7 +30,7 @@ * PHPExcel_Writer_PDF_Core * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML @@ -40,28 +40,28 @@ abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML * * @var string */ - private $_tempDir = ''; + protected $_tempDir = ''; /** * Font * * @var string */ - private $_font = 'freesans'; + protected $_font = 'freesans'; /** * Orientation (Over-ride) * * @var string */ - private $_orientation = NULL; + protected $_orientation = NULL; /** * Paper size (Over-ride) * * @var int */ - private $_paperSize = NULL; + protected $_paperSize = NULL; /** diff --git a/Classes/PHPExcel/Writer/PDF/DomPDF.php b/Classes/PHPExcel/Writer/PDF/DomPDF.php index a1ae443a..d03b758c 100644 --- a/Classes/PHPExcel/Writer/PDF/DomPDF.php +++ b/Classes/PHPExcel/Writer/PDF/DomPDF.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -38,7 +38,7 @@ if (file_exists($pdfRendererClassFile)) { * PHPExcel_Writer_PDF_DomPDF * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter diff --git a/Classes/PHPExcel/Writer/PDF/mPDF.php b/Classes/PHPExcel/Writer/PDF/mPDF.php index e885c6e2..53dd9122 100644 --- a/Classes/PHPExcel/Writer/PDF/mPDF.php +++ b/Classes/PHPExcel/Writer/PDF/mPDF.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -38,7 +38,7 @@ if (file_exists($pdfRendererClassFile)) { * PHPExcel_Writer_PDF_mPDF * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter diff --git a/Classes/PHPExcel/Writer/PDF/tcPDF.php b/Classes/PHPExcel/Writer/PDF/tcPDF.php index 7c0c537b..4119af87 100644 --- a/Classes/PHPExcel/Writer/PDF/tcPDF.php +++ b/Classes/PHPExcel/Writer/PDF/tcPDF.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## @@ -39,7 +39,7 @@ if (file_exists($pdfRendererClassFile)) { * PHPExcel_Writer_PDF_tcPDF * * @category PHPExcel - * @package PHPExcel_Writer + * @package PHPExcel_Writer_PDF * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter