From 53b7bc5b382752cafa50688c075b3b8aac1d781e Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Thu, 9 Apr 2009 08:44:20 +0000 Subject: [PATCH] caching removed due memleaks in bidder git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@70 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Format.class.php | 75 +++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/classes/Format.class.php b/classes/Format.class.php index aa3f12a..92a11a7 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -23,13 +23,11 @@ class Format static protected $date_format = 'd.m.Y'; static protected $date_time_format = 'H:i d.m.Y'; static protected $timezone_offset = 0; - static protected $cache_time = array(); /* money */ static protected $decimal_point = ','; static protected $currency_symbol = 'руб.'; static protected $frac_digits = 2; - static protected $cache_money = array(); static public function getCurrency() { @@ -45,25 +43,19 @@ class Format */ static public function int2money($int = 0, $currency = false, $show_decimals = true) { - $key = $int . '_' . (int)$currency . '_' . (int)$show_decimals; - - if(!isset(self::$cache_money[$key])){ - self::$cache_money[$key] = number_format($int/100, ($show_decimals) ? self::$frac_digits : 0, self::$decimal_point, ' '); - } - return self::$cache_money[$key] . (($currency) ? ' '.self::$currency_symbol : ''); + $money = number_format($int/100, ($show_decimals) ? self::$frac_digits : 0, self::$decimal_point, ' '); + return $money . (($currency) ? ' '.self::$currency_symbol : ''); } static public function money2int($money) { $money = str_replace(' ', '', $money); - if(!isset(self::$cache_money[$money])){ - if(!strstr($money, self::$decimal_point) && !strstr($money, '.')){ - self::$cache_money[$money] = (int)$money * 100; - }else{ - self::$cache_money[$money] = (int)str_replace(array('.', self::$decimal_point), '', $money); - } + if(!strstr($money, self::$decimal_point) && !strstr($money, '.')){ + $int = (int)$money * 100; + }else{ + $int = (int)str_replace(array('.', self::$decimal_point), '', $money); } - return self::$cache_money[$money]; + return $int; } @@ -75,10 +67,8 @@ class Format */ static public function int2time($timestamp = 0) { - if(!isset(self::$cache_time[$timestamp])){ - self::$cache_time[$timestamp] = date(self::$time_format, $timestamp-self::$timezone_offset); - } - return self::$cache_time[$timestamp]; + $time = date(self::$time_format, $timestamp - self::$timezone_offset); + return $time; } /** @@ -90,20 +80,18 @@ class Format */ static public function int2date($timestamp = 0, $hours = true) { - if(!isset(self::$cache_time[$timestamp])){ - self::$cache_time[$timestamp] = date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); - } - return self::$cache_time[$timestamp]; + $date = date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); + return $date; } static public function int2rusDate($timestamp = 0, $hours = false) { - $month = array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"); - - if(!isset(self::$cache_time[$timestamp])){ - self::$cache_time[$timestamp] = ($hours) ? date("H:i d", $timestamp) . " " . $month[date("m", $timestamp) - 1] . " " .date("Y", $timestamp) : date("d", $timestamp) . " " . $month[date("m", $timestamp) - 1] . " " .date("Y", $timestamp); - } - return self::$cache_time[$timestamp]; + $month = array('января', 'февраля', 'марта', + 'апреля', 'мая', 'июня', + 'июля', 'августа', 'сентября', + 'октября', 'ноября', 'декабря'); + $date = ($hours) ? date('H:i d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp) : date('d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp); + return $date; } /** @@ -124,16 +112,14 @@ class Format */ static public function time2int($time) { - if(!isset(self::$cache_time[$time])){ - $elements = explode(':', $time); - if(count($elements) == 3){ - list($h, $m, $s) = $elements; - self::$cache_time[$time] = ($h * 60 * 60) + ($m * 60) + $s; - } else { - self::$cache_time[$time] = (int)$time; - } + $elements = explode(':', $time); + if(count($elements) == 3){ + list($h, $m, $s) = $elements; + $int = ($h * 60 * 60) + ($m * 60) + $s; + } else { + $int = (int)$time; } - return self::$cache_time[$time]; + return $int; } /** @@ -144,10 +130,7 @@ class Format */ static public function date2int($time) { - if(!isset(self::$cache_time[$time])){ - self::$cache_time[$time] = strtotime($time); - } - return self::$cache_time[$time]; + return strtotime($time); } static public function int2phone($intphone) @@ -155,20 +138,20 @@ class Format $intphone = (string) $intphone; if (strlen($intphone) == 10) { - return '('.substr($intphone, 0, 3).') '.substr($intphone, 3, 3).'-'.substr($intphone, 6, 2).'-'.substr($intphone, 8, 2); + return '(' . substr($intphone, 0, 3) . ') ' . substr($intphone, 3, 3) . '-' . substr($intphone, 6, 2) . '-' . substr($intphone, 8, 2); } elseif (strlen($intphone) == 7) { - return substr($intphone, 0, 3).'-'.substr($intphone, 3, 2).'-'.substr($intphone, 5, 2); + return substr($intphone, 0, 3) . '-' . substr($intphone, 3, 2) . '-' . substr($intphone, 5, 2); } return ''; } static public function phone2int($phone) { - $phone = str_replace(array(' ','-','(',')'), '', $phone); + $phone = str_replace(array(' ', '-', '(', ')'), '', $phone); $phone_length = strlen($phone); if (is_numeric($phone) && ($phone_length == 7 || $phone_length == 10)) { //бывают семизначные прямые номера if ($phone_length == 7) { - $phone = '495'.$phone; + $phone = '495' . $phone; } return $phone; }