From 59e85a379d297a16e5b109d46137c5e14083b6ad Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 25 Jan 2011 23:11:32 +0000 Subject: [PATCH] Added flushInstance() method to clear the calculation cache, but only if the calculation engine has been instantiated. Moved precision setting from functions.php to the calculation engine constructor, with a reset when the calculation engine instance is unset... will be of value when I switch the code to support a calculation engine/cache with each instantiated PHPExcel object. git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@67403 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Calculation.php | 29 +++++++++++++++++++++- Classes/PHPExcel/Calculation/Functions.php | 6 ----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Classes/PHPExcel/Calculation.php b/Classes/PHPExcel/Calculation.php index 60dca6ef..0c2d2a63 100644 --- a/Classes/PHPExcel/Calculation.php +++ b/Classes/PHPExcel/Calculation.php @@ -202,6 +202,9 @@ class PHPExcel_Calculation { public $cyclicFormulaCount = 0; + private $_savedPrecision = 12; + + private static $_localeLanguage = 'en_us'; // US English (default locale) private static $_validLocaleLanguages = array( 'en' // English (default language) ); @@ -1664,7 +1667,7 @@ class PHPExcel_Calculation { - function __construct() { + private function __construct() { $localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/'; foreach (glob($localeFileDirectory.'/*',GLOB_ONLYDIR) as $filename) { $filename = substr($filename,strlen($localeFileDirectory)+1); @@ -1672,9 +1675,19 @@ class PHPExcel_Calculation { self::$_validLocaleLanguages[] = $filename; } } + + $setPrecision = (PHP_INT_SIZE == 4) ? 12 : 16; + $this->_savedPrecision = ini_get('precision'); + if ($savedPrecision < $setPrecision) { + ini_set('precision',$setPrecision); + } } // function __construct() + public function __destruct() { + ini_set('precision',$this->_savedPrecision); + } + /** * Get an instance of this class * @@ -1690,6 +1703,20 @@ class PHPExcel_Calculation { } // function getInstance() + /** + * Flush the calculation cache for any existing instance of this class + * but only if a PHPExcel_Calculation instance exists + * + * @access public + * @return null + */ + public static function flushInstance() { + if (isset(self::$_instance) && !is_null(self::$_instance)) { + self::$_instance->clearCalculationCache(); + } + } // function flushInstance() + + /** * __clone implementation. Cloning should not be allowed in a Singleton! * diff --git a/Classes/PHPExcel/Calculation/Functions.php b/Classes/PHPExcel/Calculation/Functions.php index 8b8d7cd8..a81705ef 100644 --- a/Classes/PHPExcel/Calculation/Functions.php +++ b/Classes/PHPExcel/Calculation/Functions.php @@ -49,12 +49,6 @@ define('MAX_ITERATIONS', 256); define('PRECISION', 8.88E-016); -$savedPrecision = ini_get('precision'); -if ($savedPrecision < 16) { - ini_set('precision',16); -} - - /** * PHPExcel_Calculation_Functions *