From 69550c5525efa018fb89ca15e979a7e76608a117 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 19 May 2014 13:45:02 +0200 Subject: Fix caching of MIME config * in get_mimes(): was missing isset() test * in Email->_mimes_types(): static cache of reference was noneffective refs 6ef498b49946ba74d610b3805fb908b163a7f03a --- system/core/Common.php | 21 ++++++++++++++------- system/libraries/Email.php | 9 ++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 7f2708151..752a2e7f1 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -304,15 +304,22 @@ if ( ! function_exists('get_mimes')) */ function &get_mimes() { - static $_mimes = array(); + static $_mimes; - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + if (empty($_mimes)) { - $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); - } - elseif (file_exists(APPPATH.'config/mimes.php')) - { - $_mimes = include(APPPATH.'config/mimes.php'); + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) + { + $_mimes = include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); + } + elseif (file_exists(APPPATH.'config/mimes.php')) + { + $_mimes = include(APPPATH.'config/mimes.php'); + } + else + { + $_mimes = array(); + } } return $_mimes; diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1f2f6a991..011a88c22 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2234,15 +2234,18 @@ class CI_Email { */ protected function _mime_types($ext = '') { - static $mimes; + static $_mimes; $ext = strtolower($ext); - if ( ! is_array($mimes)) + if (empty($_mimes)) { - $mimes =& get_mimes(); + // references cannot be directly assigned to static variables, so we use an array + $_mimes[0] =& get_mimes(); } + $mimes =& $_mimes[0]; + if (isset($mimes[$ext])) { return is_array($mimes[$ext]) -- cgit v1.2.3-24-g4f1b From 66c7bb41310ea7543cfeac5b008fa24d30e962e1 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 19 May 2014 13:45:12 +0200 Subject: Remove static cache in Email->_mimes_types() Saving one function call isn't worth the code overhead. --- system/libraries/Email.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 011a88c22..63b7dc31c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -2234,17 +2234,9 @@ class CI_Email { */ protected function _mime_types($ext = '') { - static $_mimes; - $ext = strtolower($ext); - if (empty($_mimes)) - { - // references cannot be directly assigned to static variables, so we use an array - $_mimes[0] =& get_mimes(); - } - - $mimes =& $_mimes[0]; + $mimes =& get_mimes(); if (isset($mimes[$ext])) { -- cgit v1.2.3-24-g4f1b