From 1e0d1aaa38305f04cb371a94341ea6ac13d1e07a Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Mon, 19 Nov 2012 18:40:04 +0400 Subject: [PATCH] PHPDocs for cache, Format --- cache/Cache.php | 35 ++++++++++++++-------------- cache/CacheKey.php | 3 ++- cache/Cacher.php | 6 +++++ cache/MemcacheCache.php | 59 +++++++++++++++++++++++++----------------------- classes/Format.class.php | 3 ++- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/cache/Cache.php b/cache/Cache.php index b2196ea..f68d10b 100644 --- a/cache/Cache.php +++ b/cache/Cache.php @@ -11,72 +11,71 @@ abstract class Cache { - + /** * Add an item to the cache - * + * * @param string $key * @param mixed $value * @param int $expire * @return bool */ abstract public function add($key, $value, $expire = 0); - + /** * Decrement item's value - * + * * @param string $key * @param int $decrement * @return bool */ abstract public function decrement($key, $decrement = 1); - + /** * Delete item from the cache - * + * * @param string $key - * @param int $value * @return bool */ abstract public function del($key); - + /** * Flush all existing items - * + * * @return bool */ abstract public function flush(); - + /** * Retrieve item from the cache - * + * * @param mixed $key * @return mixed */ abstract public function get($key); - + /** * Increment item's value - * + * * @param string $key * @param int $increment * @return bool */ abstract public function increment($key, $increment = 1); - + /** * Replace value of the existing item - * + * * @param string $key - * @param mixed $var + * @param mixed $value * @param int $expire * @return bool */ abstract public function replace($key, $value, $expire = 0); - + /** * Store data in the cache - * + * * @param string $key * @param mixed $value * @param int $expire diff --git a/cache/CacheKey.php b/cache/CacheKey.php index 8121026..d7a4aeb 100644 --- a/cache/CacheKey.php +++ b/cache/CacheKey.php @@ -13,7 +13,7 @@ class CacheKey { /** - * @var Cacher + * @var Cache */ protected $cacher; @@ -62,6 +62,7 @@ class CacheKey /** * @param mixed $value + * @return bool */ public function set($value) { diff --git a/cache/Cacher.php b/cache/Cacher.php index b662c57..0d35887 100644 --- a/cache/Cacher.php +++ b/cache/Cacher.php @@ -19,6 +19,12 @@ class Cacher */ static protected $caches = array(); + /** + * @param $cacher + * @param null|string $config + * @return Cache + * @throws InitializationException + */ static public function get($cacher, $config = null) { if (!isset(self::$caches[$cacher])) { diff --git a/cache/MemcacheCache.php b/cache/MemcacheCache.php index 4b2e61f..aa6b5cc 100644 --- a/cache/MemcacheCache.php +++ b/cache/MemcacheCache.php @@ -11,31 +11,33 @@ class MemcacheCache extends Cache { - + /** * @var Memcache */ protected $connection = null; - + + /** + * @var null|string + */ protected $key_salt = null; - + /** * One hour to live default - * + * * @var int */ protected $expire = 3600; - - + public function __construct($config) { $this->connection = new Memcache(); - + if (isset($config['key_salt'])) { $this->key_salt = $config['key_salt']; unset($config['key_salt']); } - + $required = array('hostname', 'port'); foreach ($config as $c) { foreach ($required as $option) { @@ -46,10 +48,10 @@ class MemcacheCache extends Cache $this->connection->addServer($c['hostname'], $c['port']); } } - + /** * Add an item to the cache - * + * * @param string $key * @param mixed $value * @param int $expire @@ -59,10 +61,10 @@ class MemcacheCache extends Cache { return $this->connection->add($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * Decrement item's value - * + * * @param string $key * @param int $decrement * @return bool @@ -71,32 +73,32 @@ class MemcacheCache extends Cache { return $this->connection->decrement($this->getKey($key), $decrement); } - + /** * Delete item from the cache - * + * * @param string $key - * @param int $value + * @internal param int $value * @return bool */ public function del($key) { return $this->connection->delete($this->getKey($key), 0); } - + /** * Flush all existing items - * + * * @return bool */ public function flush() { return $this->connection->flush(); } - + /** * Retrieve item from the cache - * + * * @param string $key * @return mixed */ @@ -104,10 +106,10 @@ class MemcacheCache extends Cache { return $this->connection->get($this->getKey($key)); } - + /** * Increment item's value - * + * * @param string $key * @param int $increment * @return bool @@ -116,23 +118,24 @@ class MemcacheCache extends Cache { return $this->connection->increment($this->getKey($key), $increment); } - + /** * Replace value of the existing item - * + * * @param string $key - * @param mixed $var + * @param mixed $value * @param int $expire + * @internal param mixed $var * @return bool */ public function replace($key, $value, $expire = 0) { return $this->connection->replace($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * Store data in the cache - * + * * @param string $key * @param mixed $value * @param int $expire @@ -142,7 +145,7 @@ class MemcacheCache extends Cache { return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire)); } - + /** * @param string $key * @return string @@ -151,7 +154,7 @@ class MemcacheCache extends Cache { return md5($this->key_salt . $key); } - + public function getExpire($expire) { return ($expire > 0) ? $expire : $this->expire; diff --git a/classes/Format.class.php b/classes/Format.class.php index 215ef30..fbefc25 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -47,6 +47,7 @@ class Format * @param mixed $int * @param bool $currency - показывать валюту * @param bool $show_decimals - показывать или нет дробную часть + * @return string */ static public function int2money($int = 0, $currency = false, $show_decimals = true) { @@ -169,7 +170,7 @@ class Format * Преобразует дату в таймстамп. * * @param mixed $time - * @return TimeFormat + * @return int|bool */ static public function date2int($time) {