PHPDocs for cache, Format

This commit is contained in:
Anton Terekhov
2012-11-19 18:40:04 +04:00
parent 2d02f25e22
commit 1e0d1aaa38
5 changed files with 58 additions and 48 deletions

35
cache/Cache.php vendored
View File

@ -11,72 +11,71 @@
abstract class Cache abstract class Cache
{ {
/** /**
* Add an item to the cache * Add an item to the cache
* *
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @param int $expire * @param int $expire
* @return bool * @return bool
*/ */
abstract public function add($key, $value, $expire = 0); abstract public function add($key, $value, $expire = 0);
/** /**
* Decrement item's value * Decrement item's value
* *
* @param string $key * @param string $key
* @param int $decrement * @param int $decrement
* @return bool * @return bool
*/ */
abstract public function decrement($key, $decrement = 1); abstract public function decrement($key, $decrement = 1);
/** /**
* Delete item from the cache * Delete item from the cache
* *
* @param string $key * @param string $key
* @param int $value
* @return bool * @return bool
*/ */
abstract public function del($key); abstract public function del($key);
/** /**
* Flush all existing items * Flush all existing items
* *
* @return bool * @return bool
*/ */
abstract public function flush(); abstract public function flush();
/** /**
* Retrieve item from the cache * Retrieve item from the cache
* *
* @param mixed $key * @param mixed $key
* @return mixed * @return mixed
*/ */
abstract public function get($key); abstract public function get($key);
/** /**
* Increment item's value * Increment item's value
* *
* @param string $key * @param string $key
* @param int $increment * @param int $increment
* @return bool * @return bool
*/ */
abstract public function increment($key, $increment = 1); abstract public function increment($key, $increment = 1);
/** /**
* Replace value of the existing item * Replace value of the existing item
* *
* @param string $key * @param string $key
* @param mixed $var * @param mixed $value
* @param int $expire * @param int $expire
* @return bool * @return bool
*/ */
abstract public function replace($key, $value, $expire = 0); abstract public function replace($key, $value, $expire = 0);
/** /**
* Store data in the cache * Store data in the cache
* *
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @param int $expire * @param int $expire

3
cache/CacheKey.php vendored
View File

@ -13,7 +13,7 @@ class CacheKey
{ {
/** /**
* @var Cacher * @var Cache
*/ */
protected $cacher; protected $cacher;
@ -62,6 +62,7 @@ class CacheKey
/** /**
* @param mixed $value * @param mixed $value
* @return bool
*/ */
public function set($value) public function set($value)
{ {

6
cache/Cacher.php vendored
View File

@ -19,6 +19,12 @@ class Cacher
*/ */
static protected $caches = array(); static protected $caches = array();
/**
* @param $cacher
* @param null|string $config
* @return Cache
* @throws InitializationException
*/
static public function get($cacher, $config = null) static public function get($cacher, $config = null)
{ {
if (!isset(self::$caches[$cacher])) { if (!isset(self::$caches[$cacher])) {

View File

@ -11,31 +11,33 @@
class MemcacheCache extends Cache class MemcacheCache extends Cache
{ {
/** /**
* @var Memcache * @var Memcache
*/ */
protected $connection = null; protected $connection = null;
/**
* @var null|string
*/
protected $key_salt = null; protected $key_salt = null;
/** /**
* One hour to live default * One hour to live default
* *
* @var int * @var int
*/ */
protected $expire = 3600; protected $expire = 3600;
public function __construct($config) public function __construct($config)
{ {
$this->connection = new Memcache(); $this->connection = new Memcache();
if (isset($config['key_salt'])) { if (isset($config['key_salt'])) {
$this->key_salt = $config['key_salt']; $this->key_salt = $config['key_salt'];
unset($config['key_salt']); unset($config['key_salt']);
} }
$required = array('hostname', 'port'); $required = array('hostname', 'port');
foreach ($config as $c) { foreach ($config as $c) {
foreach ($required as $option) { foreach ($required as $option) {
@ -46,10 +48,10 @@ class MemcacheCache extends Cache
$this->connection->addServer($c['hostname'], $c['port']); $this->connection->addServer($c['hostname'], $c['port']);
} }
} }
/** /**
* Add an item to the cache * Add an item to the cache
* *
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @param int $expire * @param int $expire
@ -59,10 +61,10 @@ class MemcacheCache extends Cache
{ {
return $this->connection->add($this->getKey($key), $value, null, $this->getExpire($expire)); return $this->connection->add($this->getKey($key), $value, null, $this->getExpire($expire));
} }
/** /**
* Decrement item's value * Decrement item's value
* *
* @param string $key * @param string $key
* @param int $decrement * @param int $decrement
* @return bool * @return bool
@ -71,32 +73,32 @@ class MemcacheCache extends Cache
{ {
return $this->connection->decrement($this->getKey($key), $decrement); return $this->connection->decrement($this->getKey($key), $decrement);
} }
/** /**
* Delete item from the cache * Delete item from the cache
* *
* @param string $key * @param string $key
* @param int $value * @internal param int $value
* @return bool * @return bool
*/ */
public function del($key) public function del($key)
{ {
return $this->connection->delete($this->getKey($key), 0); return $this->connection->delete($this->getKey($key), 0);
} }
/** /**
* Flush all existing items * Flush all existing items
* *
* @return bool * @return bool
*/ */
public function flush() public function flush()
{ {
return $this->connection->flush(); return $this->connection->flush();
} }
/** /**
* Retrieve item from the cache * Retrieve item from the cache
* *
* @param string $key * @param string $key
* @return mixed * @return mixed
*/ */
@ -104,10 +106,10 @@ class MemcacheCache extends Cache
{ {
return $this->connection->get($this->getKey($key)); return $this->connection->get($this->getKey($key));
} }
/** /**
* Increment item's value * Increment item's value
* *
* @param string $key * @param string $key
* @param int $increment * @param int $increment
* @return bool * @return bool
@ -116,23 +118,24 @@ class MemcacheCache extends Cache
{ {
return $this->connection->increment($this->getKey($key), $increment); return $this->connection->increment($this->getKey($key), $increment);
} }
/** /**
* Replace value of the existing item * Replace value of the existing item
* *
* @param string $key * @param string $key
* @param mixed $var * @param mixed $value
* @param int $expire * @param int $expire
* @internal param mixed $var
* @return bool * @return bool
*/ */
public function replace($key, $value, $expire = 0) public function replace($key, $value, $expire = 0)
{ {
return $this->connection->replace($this->getKey($key), $value, null, $this->getExpire($expire)); return $this->connection->replace($this->getKey($key), $value, null, $this->getExpire($expire));
} }
/** /**
* Store data in the cache * Store data in the cache
* *
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @param int $expire * @param int $expire
@ -142,7 +145,7 @@ class MemcacheCache extends Cache
{ {
return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire)); return $this->connection->set($this->getKey($key), $value, null, $this->getExpire($expire));
} }
/** /**
* @param string $key * @param string $key
* @return string * @return string
@ -151,7 +154,7 @@ class MemcacheCache extends Cache
{ {
return md5($this->key_salt . $key); return md5($this->key_salt . $key);
} }
public function getExpire($expire) public function getExpire($expire)
{ {
return ($expire > 0) ? $expire : $this->expire; return ($expire > 0) ? $expire : $this->expire;

View File

@ -47,6 +47,7 @@ class Format
* @param mixed $int * @param mixed $int
* @param bool $currency - показывать валюту * @param bool $currency - показывать валюту
* @param bool $show_decimals - показывать или нет дробную часть * @param bool $show_decimals - показывать или нет дробную часть
* @return string
*/ */
static public function int2money($int = 0, $currency = false, $show_decimals = true) static public function int2money($int = 0, $currency = false, $show_decimals = true)
{ {
@ -169,7 +170,7 @@ class Format
* Преобразует дату в таймстамп. * Преобразует дату в таймстамп.
* *
* @param mixed $time * @param mixed $time
* @return TimeFormat * @return int|bool
*/ */
static public function date2int($time) static public function date2int($time)
{ {