From 17c589ff999c901600d57cccc02e429855f502e2 Mon Sep 17 00:00:00 2001 From: Georges Limouzy Date: Tue, 2 Feb 2016 02:29:01 +0100 Subject: [PATCH] Global changes: - Added phpDoc Block comment on class/method/properties - Replaced **var** keyword with **public** - Defined non-existing visibility (public, protected, private) - Moved constructor to be first method position - Commented unused/emty if/else conditions - Improved return consistency, e.g: phpfastcache_xcache::driver_isExisting() - Removed aliases: - is_writeable() => is_writable() - Removed tab indentations (it hurt eyes so bad) - Removed silent operator (as per #175): - sqlite.php - file_exists() - mkdir() - Ignored: - phpfastcache/_extensions/predis-1.0/* - phpfastcache/_extensions/SSDB.php --- example.php | 15 +- example2.php | 24 +- phpfastcache/3.0.0/abstract.php | 536 +++++++++++++++-------- phpfastcache/3.0.0/driver.php | 78 ++-- phpfastcache/3.0.0/drivers/apc.php | 122 ++++-- phpfastcache/3.0.0/drivers/cookie.php | 237 +++++----- phpfastcache/3.0.0/drivers/example.php | 96 ++-- phpfastcache/3.0.0/drivers/files.php | 298 ++++++++----- phpfastcache/3.0.0/drivers/memcache.php | 199 +++++---- phpfastcache/3.0.0/drivers/memcached.php | 190 +++++--- phpfastcache/3.0.0/drivers/predis.php | 290 ++++++------ phpfastcache/3.0.0/drivers/redis.php | 295 +++++++------ phpfastcache/3.0.0/drivers/sqlite.php | 352 +++++++++------ phpfastcache/3.0.0/drivers/ssdb.php | 146 +++--- phpfastcache/3.0.0/drivers/wincache.php | 104 +++-- phpfastcache/3.0.0/drivers/xcache.php | 124 ++++-- phpfastcache/3.0.0/extensions.php | 14 +- phpfastcache/3.0.0/phpfastcache.php | 408 ++++++++++------- phpfastcache/_extensions/regex.php | 11 +- 19 files changed, 2210 insertions(+), 1329 deletions(-) diff --git a/example.php b/example.php index 87b0fe561..32e19954b 100644 --- a/example.php +++ b/example.php @@ -1,8 +1,9 @@ http://www.phpfastcache.com */ // Require Library @@ -15,15 +16,15 @@ // product_page is "identity keyword"; $products = $cache->get("product_page"); -if($products == null) { - $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS"; - // Write products to Cache in 10 minutes with same keyword - $cache->set("product_page",$products , 600); +if ($products == null) { + $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS"; + // Write products to Cache in 10 minutes with same keyword + $cache->set("product_page", $products, 600); - echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> "; + echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> "; } else { - echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> "; + echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> "; } // use your products here or return it; diff --git a/example2.php b/example2.php index 12047b801..9b57f64b5 100644 --- a/example2.php +++ b/example2.php @@ -1,8 +1,9 @@ http://www.phpfastcache.com */ // Require Library @@ -11,31 +12,30 @@ // simple Caching with: $cache = phpFastCache("redis"); -if($cache->fallback === true) { - echo " USE BACK UP DRIVER = ".phpFastCache::$config['fallback']."
"; +if ($cache->fallback === true) { + echo " USE BACK UP DRIVER = " . phpFastCache::$config[ 'fallback' ] . "
"; } else { - echo ' DRIVER IS GOOD
'; + echo ' DRIVER IS GOOD
'; } - // Try to get $products from Caching First // product_page is "identity keyword"; $products = $cache->get("product_page2"); -if($products == null) { - $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS"; - // Write products to Cache in 10 minutes with same keyword - $cache->set("product_page2",$products , 2); +if ($products == null) { + $products = "DB QUERIES | FUNCTION_GET_PRODUCTS | ARRAY | STRING | OBJECTS"; + // Write products to Cache in 10 minutes with same keyword + $cache->set("product_page2", $products, 2); - echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> "; + echo " --> NO CACHE ---> DB | Func | API RUN FIRST TIME ---> "; } else { - echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> "; + echo " --> USE CACHE --> SERV 10,000+ Visitors FROM CACHE ---> "; } // use your products here or return it; -echo "Products = ".$products; +echo "Products = " . $products; diff --git a/phpfastcache/3.0.0/abstract.php b/phpfastcache/3.0.0/abstract.php index 517220898..ca4d96b84 100644 --- a/phpfastcache/3.0.0/abstract.php +++ b/phpfastcache/3.0.0/abstract.php @@ -1,97 +1,150 @@ http://www.phpfastcache.com + */ +abstract class BasePhpFastCache +{ + + /** + * @var array + */ + public $tmp = array(); - // default options, this will be merge to Driver's Options - var $config = array(); + /** + * @var array default options, this will be merge to Driver's Options + */ + public $config = array(); + /** + * @var bool + */ + public $fallback = false; - var $fallback = false; - var $instant; + /** + * @var + */ + public $instant; - /* + /** * Basic Functions + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool|null */ - - public function set($keyword, $value = "", $time = 0, $option = array() ) { - /* + public function set($keyword, $value = "", $time = 0, $option = array()) + { + /** * Infinity Time * Khoa. B */ - if((Int)$time <= 0) { + if ((int)$time <= 0) { // 5 years, however memcached or memory cached will gone when u restart it // just recommended for sqlite. files - $time = 3600*24*365*5; + $time = 3600 * 24 * 365 * 5; } /* * Temporary disabled phpFastCache::$disabled = true * Khoa. B */ - if(phpFastCache::$disabled === true) { + if (phpFastCache::$disabled === true) { return false; } $object = array( - "value" => $value, - "write_time" => time(), - "expired_in" => $time, - "expired_time" => time() + (Int)$time, + "value" => $value, + "write_time" => time(), + "expired_in" => $time, + "expired_time" => time() + (Int)$time, ); - return $this->driver_set($keyword,$object,$time,$option); + return $this->driver_set($keyword, $object, $time, $option); } - public function get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed + */ + public function get($keyword, $option = array()) + { /* * Temporary disabled phpFastCache::$disabled = true * Khoa. B */ - if(phpFastCache::$disabled === true) { + if (phpFastCache::$disabled === true) { return null; } - $object = $this->driver_get($keyword,$option); + $object = $this->driver_get($keyword, $option); - if($object == null) { + if ($object == null) { return null; } - - $value = isset( $object['value'] ) ? $object['value'] : null; - return isset( $option['all_keys'] ) && $option['all_keys'] ? $object : $value; - } + $value = isset($object[ 'value' ]) ? $object[ 'value' ] : null; + return isset($option[ 'all_keys' ]) && $option[ 'all_keys' ] ? $object : $value; + } - function getInfo($keyword, $option = array()) { - $object = $this->driver_get($keyword,$option); + /** + * @param $keyword + * @param array $option + * @return null|object + */ + public function getInfo($keyword, $option = array()) + { + $object = $this->driver_get($keyword, $option); - if($object == null) { + if ($object == null) { return null; } return $object; } - function delete($keyword, $option = array()) { - return $this->driver_delete($keyword,$option); + /** + * @param $keyword + * @param array $option + * @return mixed + */ + public function delete($keyword, $option = array()) + { + return $this->driver_delete($keyword, $option); } - function stats($option = array()) { + /** + * @param array $option + * @return mixed + */ + public function stats($option = array()) + { return $this->driver_stats($option); } - function clean($option = array()) { + /** + * @param array $option + * @return mixed + */ + public function clean($option = array()) + { return $this->driver_clean($option); } - function isExisting($keyword) { - if(method_exists($this,"driver_isExisting")) { + /** + * @param $keyword + * @return bool + */ + public function isExisting($keyword) + { + if (method_exists($this, "driver_isExisting")) { return $this->driver_isExisting($keyword); } $data = $this->get($keyword); - if($data == null) { + if ($data == null) { return false; } else { return true; @@ -99,185 +152,288 @@ function isExisting($keyword) { } - // Searches though the cache for keys that match the given query. - // todo: search - function search($query) { - if(method_exists($this,"driver_search")) { + /** + * Searches though the cache for keys that match the given query. + * todo: search + * @param $query + * @return mixed + * @throws \Exception + */ + public function search($query) + { + if (method_exists($this, "driver_search")) { return $this->driver_search($query); } throw new Exception('Search method is not supported by this driver.'); } - function increment($keyword, $step = 1 , $option = array()) { + /** + * @param $keyword + * @param int $step + * @param array $option + * @return bool + */ + public function increment($keyword, $step = 1, $option = array()) + { $object = $this->get($keyword, array('all_keys' => true)); - if($object == null) { + if ($object == null) { return false; } else { - $value = (Int)$object['value'] + (Int)$step; - $time = $object['expired_time'] - time(); - $this->set($keyword,$value, $time, $option); + $value = (Int)$object[ 'value' ] + (Int)$step; + $time = $object[ 'expired_time' ] - time(); + $this->set($keyword, $value, $time, $option); return true; } } - function decrement($keyword, $step = 1 , $option = array()) { + /** + * @param $keyword + * @param int $step + * @param array $option + * @return bool + */ + public function decrement($keyword, $step = 1, $option = array()) + { $object = $this->get($keyword, array('all_keys' => true)); - if($object == null) { + if ($object == null) { return false; } else { - $value = (Int)$object['value'] - (Int)$step; - $time = $object['expired_time'] - time(); - $this->set($keyword,$value, $time, $option); + $value = (Int)$object[ 'value' ] - (Int)$step; + $time = $object[ 'expired_time' ] - time(); + $this->set($keyword, $value, $time, $option); return true; } } - /* + + /** * Extend more time + * @param $keyword + * @param int $time + * @param array $option + * @return bool */ - function touch($keyword, $time = 300, $option = array()) { + public function touch($keyword, $time = 300, $option = array()) + { $object = $this->get($keyword, array('all_keys' => true)); - if($object == null) { + if ($object == null) { return false; } else { - $value = $object['value']; - $time = $object['expired_time'] - time() + $time; - $this->set($keyword, $value,$time, $option); + $value = $object[ 'value' ]; + $time = $object[ 'expired_time' ] - time() + $time; + $this->set($keyword, $value, $time, $option); return true; } } - /* - * Other Functions Built-int for phpFastCache since 1.3 - */ + /** + * Other Functions Built-int for phpFastCache since 1.3 + */ - public function setMulti($list = array()) { - foreach($list as $array) { - $this->set($array[0], isset($array[1]) ? $array[1] : 0, isset($array[2]) ? $array[2] : array()); + /** + * @param array $list + */ + public function setMulti($list = array()) + { + foreach ($list as $array) { + $this->set($array[ 0 ], isset($array[ 1 ]) ? $array[ 1 ] : 0, + isset($array[ 2 ]) ? $array[ 2 ] : array()); } } - public function getMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function getMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->get($name, isset($array[1]) ? $array[1] : array()); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->get($name, + isset($array[ 1 ]) ? $array[ 1 ] : array()); } return $res; } - public function getInfoMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function getInfoMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->getInfo($name, isset($array[1]) ? $array[1] : array()); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->getInfo($name, + isset($array[ 1 ]) ? $array[ 1 ] : array()); } return $res; } - public function deleteMulti($list = array()) { - foreach($list as $array) { - $this->delete($array[0], isset($array[1]) ? $array[1] : array()); + /** + * @param array $list + */ + public function deleteMulti($list = array()) + { + foreach ($list as $array) { + $this->delete($array[ 0 ], + isset($array[ 1 ]) ? $array[ 1 ] : array()); } } - public function isExistingMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function isExistingMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->isExisting($name); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->isExisting($name); } return $res; } - public function incrementMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function incrementMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->increment($name, $array[1], isset($array[2]) ? $array[2] : array()); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->increment($name, $array[ 1 ], + isset($array[ 2 ]) ? $array[ 2 ] : array()); } return $res; } - public function decrementMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function decrementMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->decrement($name, $array[1], isset($array[2]) ? $array[2] : array()); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->decrement($name, $array[ 1 ], + isset($array[ 2 ]) ? $array[ 2 ] : array()); } return $res; } - public function touchMulti($list = array()) { + /** + * @param array $list + * @return array + */ + public function touchMulti($list = array()) + { $res = array(); - foreach($list as $array) { - $name = $array[0]; - $res[$name] = $this->touch($name, $array[1], isset($array[2]) ? $array[2] : array()); + foreach ($list as $array) { + $name = $array[ 0 ]; + $res[ $name ] = $this->touch($name, $array[ 1 ], + isset($array[ 2 ]) ? $array[ 2 ] : array()); } return $res; } - - public function setup($config_name,$value = "") { + /** + * @param $config_name + * @param string $value + */ + public function setup($config_name, $value = "") + { /* * Config for class */ - if(is_array($config_name)) { + if (is_array($config_name)) { $this->config = $config_name; } else { - $this->config[$config_name] = $value; + $this->config[ $config_name ] = $value; } } - /* - * Magic Functions + /** + * Magic methods */ - - function __get($name) { + /** + * @param $name + * @return mixed + */ + public function __get($name) + { return $this->get($name); } - - function __set($name, $v) { - if(isset($v[1]) && is_numeric($v[1])) { - return $this->set($name,$v[0],$v[1], isset($v[2]) ? $v[2] : array() ); + /** + * @param $name + * @param $v + * @return bool|null + * @throws \Exception + */ + public function __set($name, $v) + { + if (isset($v[ 1 ]) && is_numeric($v[ 1 ])) { + return $this->set($name, $v[ 0 ], $v[ 1 ], + isset($v[ 2 ]) ? $v[ 2 ] : array()); } else { - throw new Exception("Example ->$name = array('VALUE', 300);",98); + throw new Exception("Example ->$name = array('VALUE', 300);", 98); } } - public function __call($name, $args) { - return call_user_func_array( array( $this->instant, $name ), $args ); + /** + * @param $name + * @param $args + * @return mixed + */ + public function __call($name, $args) + { + return call_user_func_array(array($this->instant, $name), $args); } - /* - * Base Functions + /** + * Base Methods */ - - protected function backup() { - return phpFastCache(phpFastCache::$config['fallback']); + /** + * @return mixed + */ + protected function backup() + { + return phpFastCache(phpFastCache::$config[ 'fallback' ]); } - - protected function required_extension($name) { - require_once(dirname(__FILE__)."/../_extensions/".$name); + /** + * @param $name + */ + protected function required_extension($name) + { + require_once(dirname(__FILE__) . "/../_extensions/" . $name); } - - protected function readfile($file) { - if(function_exists("file_get_contents")) { + /** + * @param $file + * @return string + * @throws \Exception + */ + protected function readfile($file) + { + if (function_exists("file_get_contents")) { return @file_get_contents($file); } else { $string = ""; $file_handle = @fopen($file, "r"); - if(!$file_handle) { - throw new Exception("Can't Read File",96); + if (!$file_handle) { + throw new Exception("Can't Read File", 96); } while (!feof($file_handle)) { @@ -290,28 +446,36 @@ protected function readfile($file) { } } - - - /* + /** * return PATH for Files & PDO only + * @param bool $create_path + * @return string + * @throws \Exception */ - - - public function getPath($create_path = false) { - return phpFastCache::getPath($create_path,$this->config); + public function getPath($create_path = false) + { + return phpFastCache::getPath($create_path, $this->config); } - /* - * Object for Files & SQLite + /** + * Object for Files & SQLite + * @param $data + * @return string */ - protected function encode($data) { + protected function encode($data) + { return serialize($data); } - protected function decode($value) { + /** + * @param $value + * @return mixed + */ + protected function decode($value) + { $x = @unserialize($value); - if($x == false) { + if ($x == false) { return $value; } else { return $x; @@ -319,69 +483,76 @@ protected function decode($value) { } - - /* + /** * Auto Create .htaccess to protect cache folder + * @param string $path + * @throws \Exception */ + protected function htaccessGen($path = "") + { + if ($this->option("htaccess") == true) { - protected function htaccessGen($path = "") { - if($this->option("htaccess") == true) { - - if(!@file_exists($path."/.htaccess")) { + if (!@file_exists($path . "/.htaccess")) { // echo "write me"; $html = "order deny, allow \r\n deny from all \r\n allow from 127.0.0.1"; - $f = @fopen($path."/.htaccess","w+"); - if(!$f) { - throw new Exception("Can't create .htaccess",97); + $f = @fopen($path . "/.htaccess", "w+"); + if (!$f) { + throw new Exception("Can't create .htaccess", 97); } - fwrite($f,$html); + fwrite($f, $html); fclose($f); - } else { + } /*else { // echo "got me"; - } + }*/ } } - /* - * Check phpModules or CGI - */ - - protected function isPHPModule() { - return phpFastCache::isPHPModule(); + /** + * Check phpModules or CGI + * @return bool + */ + protected function isPHPModule() + { + return phpFastCache::isPHPModule(); } - /* - * return System Information + /** + * return System Information + * @return mixed + * @throws \Exception */ - public function systemInfo() { + public function systemInfo() + { $backup_option = $this->option; - if(count($this->option("system")) == 0 ) { - $this->option['system']['driver'] = "files"; - $this->option['system']['drivers'] = array(); - $dir = @opendir(dirname(__FILE__)."/drivers/"); - if(!$dir) { - throw new Exception("Can't open file dir ext",100); + if (count($this->option("system")) == 0) { + $this->option[ 'system' ][ 'driver' ] = "files"; + $this->option[ 'system' ][ 'drivers' ] = array(); + $dir = @opendir(dirname(__FILE__) . "/drivers/"); + if (!$dir) { + throw new Exception("Can't open file dir ext", 100); } - while($file = @readdir($dir)) { - if($file!="." && $file!=".." && strpos($file,".php") !== false) { - require_once(dirname(__FILE__)."/drivers/".$file); - $namex = str_replace(".php","",$file); - $class = "phpfastcache_".$namex; - $this->option['skipError'] = true; + while ($file = @readdir($dir)) { + if ($file != "." && $file != ".." && strpos($file, + ".php") !== false + ) { + require_once(dirname(__FILE__) . "/drivers/" . $file); + $namex = str_replace(".php", "", $file); + $class = "phpfastcache_" . $namex; + $this->option[ 'skipError' ] = true; $driver = new $class($this->option); $driver->option = $this->option; - if($driver->checkdriver()) { - $this->option['system']['drivers'][$namex] = true; - $this->option['system']['driver'] = $namex; + if ($driver->checkdriver()) { + $this->option[ 'system' ][ 'drivers' ][ $namex ] = true; + $this->option[ 'system' ][ 'driver' ] = $namex; } else { - $this->option['system']['drivers'][$namex] = false; + $this->option[ 'system' ][ 'drivers' ][ $namex ] = false; } } } @@ -390,26 +561,28 @@ public function systemInfo() { /* * PDO is highest priority with SQLite */ - if($this->option['system']['drivers']['sqlite'] == true) { - $this->option['system']['driver'] = "sqlite"; + if ($this->option[ 'system' ][ 'drivers' ][ 'sqlite' ] == true) { + $this->option[ 'system' ][ 'driver' ] = "sqlite"; } - - } $example = new phpfastcache_example($this->config); - $this->option("path",$example->getPath(true)); + $this->option("path", $example->getPath(true)); $this->option = $backup_option; return $this->option; } - - protected function isExistingDriver($class) { - if(@file_exists(dirname(__FILE__)."/drivers/".$class.".php")) { - require_once(dirname(__FILE__)."/drivers/".$class.".php"); - if(class_exists("phpfastcache_".$class)) { + /** + * @param string $class + * @return bool + */ + protected function isExistingDriver($class) + { + if (@file_exists(dirname(__FILE__) . "/drivers/" . $class . ".php")) { + require_once(dirname(__FILE__) . "/drivers/" . $class . ".php"); + if (class_exists("phpfastcache_" . $class)) { return true; } } @@ -418,10 +591,11 @@ protected function isExistingDriver($class) { } - - protected function __setChmodAuto() { + /** + * @return int + */ + protected function __setChmodAuto() + { return phpFastCache::__setChmodAuto($this->config); } - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/driver.php b/phpfastcache/3.0.0/driver.php index 37b743290..4ba768245 100644 --- a/phpfastcache/3.0.0/driver.php +++ b/phpfastcache/3.0.0/driver.php @@ -1,53 +1,67 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ - - -interface phpfastcache_driver { - /* +interface phpfastcache_driver +{ + /** * Check if this Cache driver is available for server or not + * phpfastcache_driver constructor. + * @param array $config */ - function __construct($config = array()); + public function __construct($config = array()); - function checkdriver(); + /** + * @return mixed + */ + public function checkdriver(); - /* - * SET - * set a obj to cache + /** + * Set a obj to cache + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return mixed */ - function driver_set($keyword, $value = "", $time = 300, $option = array() ); + public function driver_set( + $keyword, + $value = "", + $time = 300, + $option = array() + ); - /* - * GET - * return null or value of cache + /** + * Return null or value of cache + * @param $keyword + * @param array $option + * @return mixed */ - function driver_get($keyword, $option = array()); + public function driver_get($keyword, $option = array()); - /* - * Stats + /** * Show stats of caching - * Return array ("info","size","data") + * Return array("info","size","data") + * @param array $option + * @return mixed */ - function driver_stats($option = array()); + public function driver_stats($option = array()); - /* - * Delete + /** * Delete a cache + * @param $keyword + * @param array $option + * @return mixed */ - function driver_delete($keyword, $option = array()); + public function driver_delete($keyword, $option = array()); - /* - * clean + /** * Clean up whole cache + * @param array $option + * @return mixed */ - function driver_clean($option = array()); - - - - - + public function driver_clean($option = array()); } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/apc.php b/phpfastcache/3.0.0/drivers/apc.php index 6eeec8db3..76bdb4a43 100644 --- a/phpfastcache/3.0.0/drivers/apc.php +++ b/phpfastcache/3.0.0/drivers/apc.php @@ -1,87 +1,123 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ +class phpfastcache_apc extends BasePhpFastCache implements phpfastcache_driver +{ + /** + * phpfastcache_apc constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + } -class phpfastcache_apc extends BasePhpFastCache implements phpfastcache_driver { - function checkdriver() { + /** + * @return bool + */ + public function checkdriver() + { // Check apc - if(extension_loaded('apc') && ini_get('apc.enabled')) - { + if (extension_loaded('apc') && ini_get('apc.enabled')) { return true; } else { - $this->fallback = true; + $this->fallback = true; return false; } } - function __construct($config = array()) { - $this->setup($config); - - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - } - - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - if(isset($option['skipExisting']) && $option['skipExisting'] == true) { - return apc_add($keyword,$value,$time); + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return array|bool + */ + public function driver_set( + $keyword, + $value = "", + $time = 300, + $option = array() + ) { + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + return apc_add($keyword, $value, $time); } else { - return apc_store($keyword,$value,$time); + return apc_store($keyword, $value, $time); } } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching - $data = apc_fetch($keyword,$bo); - if($bo === false) { + $data = apc_fetch($keyword, $bo); + if ($bo === false) { return null; } return $data; } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return bool|\string[] + */ + public function driver_delete($keyword, $option = array()) + { return apc_delete($keyword); } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => "", + "info" => "", + "size" => "", + "data" => "", ); try { - $res['data'] = apc_cache_info("user"); - } catch(Exception $e) { - $res['data'] = array(); + $res[ 'data' ] = apc_cache_info("user"); + } catch (Exception $e) { + $res[ 'data' ] = array(); } return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + */ + public function driver_clean($option = array()) + { @apc_clear_cache(); @apc_clear_cache("user"); } - function driver_isExisting($keyword) { - if(apc_exists($keyword)) { - return true; - } else { - return false; - } + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + return (bool) apc_exists($keyword); } - - - - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/cookie.php b/phpfastcache/3.0.0/drivers/cookie.php index a5d578b2b..5f648454f 100644 --- a/phpfastcache/3.0.0/drivers/cookie.php +++ b/phpfastcache/3.0.0/drivers/cookie.php @@ -1,106 +1,141 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com - * - * Cookie Caching on Visitors Browser */ - - -class phpfastcache_cookie extends BasePhpFastCache implements phpfastcache_driver { - - - function checkdriver() { - // Check memcache - if(function_exists("setcookie")) { - return true; - } - $this->fallback = true; - return false; - } - - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - if(class_exists("Redis")) { - $this->instant = new Redis(); - } - - } - - function connectServer() { - // for cookie check output - if(!isset($_COOKIE['phpfastcache'])) { - if(!@setcookie("phpfastcache",1,10)) { - $this->fallback = true; - } - } - - } - - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - $this->connectServer(); - $keyword = "phpfastcache_".$keyword; - return @setcookie($keyword, $this->encode($value), $time, "/"); - - } - - function driver_get($keyword, $option = array()) { - $this->connectServer(); - // return null if no caching - // return value if in caching - $keyword = "phpfastcache_".$keyword; - $x = isset($_COOKIE[$keyword]) ? $this->decode($_COOKIE['keyword']) : false; - if($x == false) { - return null; - } else { - return $x; - } - } - - function driver_delete($keyword, $option = array()) { - $this->connectServer(); - $keyword = "phpfastcache_".$keyword; - @setcookie($keyword,null,-10); - $_COOKIE[$keyword] = null; - } - - function driver_stats($option = array()) { - $this->connectServer(); - $res = array( - "info" => "", - "size" => "", - "data" => $_COOKIE - ); - - return $res; - - } - - function driver_clean($option = array()) { - $this->connectServer(); - foreach($_COOKIE as $keyword=>$value) { - if(strpos($keyword,"phpfastcache") !== false) { - @setcookie($keyword,null,-10); - $_COOKIE[$keyword] = null; - } - } - } - - function driver_isExisting($keyword) { - $this->connectServer(); - $x = $this->get($keyword); - if($x == null) { - return false; - } else { - return true; - } - } - - - +class phpfastcache_cookie extends BasePhpFastCache implements phpfastcache_driver +{ + /** + * phpfastcache_cookie constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + if (class_exists("Redis")) { + $this->instant = new Redis(); + } + + } + + /** + * @return bool + */ + public function checkdriver() + { + // Check memcache + if (function_exists("setcookie")) { + return true; + } + $this->fallback = true; + return false; + } + + /** + * + */ + public function connectServer() + { + // for cookie check output + if (!isset($_COOKIE[ 'phpfastcache' ])) { + if (!@setcookie("phpfastcache", 1, 10)) { + $this->fallback = true; + } + } + + } + + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + $this->connectServer(); + $keyword = "phpfastcache_" . $keyword; + return @setcookie($keyword, $this->encode($value), $time, "/"); + + } + + /** + * @param $keyword + * @param array $option + * @return bool|mixed|null + */ + public function driver_get($keyword, $option = array()) + { + $this->connectServer(); + // return null if no caching + // return value if in caching + $keyword = "phpfastcache_" . $keyword; + $x = isset($_COOKIE[ $keyword ]) ? $this->decode($_COOKIE[ 'keyword' ]) : false; + if ($x == false) { + return null; + } else { + return $x; + } + } + + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { + $this->connectServer(); + $keyword = "phpfastcache_" . $keyword; + @setcookie($keyword, null, -10); + $_COOKIE[ $keyword ] = null; + } + + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { + $this->connectServer(); + $res = array( + "info" => "", + "size" => "", + "data" => $_COOKIE, + ); + + return $res; + + } + + /** + * @param array $option + */ + public function driver_clean($option = array()) + { + $this->connectServer(); + foreach ($_COOKIE as $keyword => $value) { + if (strpos($keyword, "phpfastcache") !== false) { + @setcookie($keyword, null, -10); + $_COOKIE[ $keyword ] = null; + } + } + } + + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + $this->connectServer(); + $x = $this->get($keyword); + + return !($x == null); + } } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/example.php b/phpfastcache/3.0.0/drivers/example.php index 954b0bf2e..1f5a95d0f 100644 --- a/phpfastcache/3.0.0/drivers/example.php +++ b/phpfastcache/3.0.0/drivers/example.php @@ -1,34 +1,51 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ +class phpfastcache_example extends BasePhpFastCache implements phpfastcache_driver +{ + /** + * phpfastcache_example constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + throw new Exception("Can't use this driver for your website!"); + } + } -class phpfastcache_example extends BasePhpFastCache implements phpfastcache_driver { - - function checkdriver() { + /** + * @return bool + */ + public function checkdriver() + { // return true; return false; } - function connectServer() { - - } - - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - throw new Exception("Can't use this driver for your website!"); - } + /** + * + */ + public function connectServer() + { } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - if(isset($option['skipExisting']) && $option['skipExisting'] == true) { + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { // skip driver } else { // add driver @@ -36,35 +53,56 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) { } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching return null; } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => "", + "info" => "", + "size" => "", + "data" => "", ); return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + */ + public function driver_clean($option = array()) + { } - function driver_isExisting($keyword) { + /** + * @param $keyword + */ + public function driver_isExisting($keyword) + { } - - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/files.php b/phpfastcache/3.0.0/drivers/files.php index c059467d0..8a8304b75 100644 --- a/phpfastcache/3.0.0/drivers/files.php +++ b/phpfastcache/3.0.0/drivers/files.php @@ -1,40 +1,57 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ - -class phpfastcache_files extends BasePhpFastCache implements phpfastcache_driver { - - function checkdriver() { - if(is_writable($this->getPath())) { - return true; - } else { - - } - return false; - } - - /* +class phpfastcache_files extends BasePhpFastCache implements phpfastcache_driver +{ + /** * Init Cache Path + * phpfastcache_files constructor. + * @param array $config */ - function __construct($config = array()) { + public function __construct($config = array()) + { $this->setup($config); $this->getPath(); // force create path - if(!$this->checkdriver() && !isset($config['skipError'])) { + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { throw new Exception("Can't use this driver for your website!"); } } - private function encodeFilename($keyword) { - return trim(trim(preg_replace("/[^a-zA-Z0-9]+/","_",$keyword),"_")); + /** + * @return bool + */ + public function checkdriver() + { + if (is_writable($this->getPath())) { + return true; + }/* else { + + }*/ + return false; + } + + /** + * @param $keyword + * @return string + */ + private function encodeFilename($keyword) + { + return trim(trim(preg_replace("/[^a-zA-Z0-9]+/", "_", $keyword), "_")); // return rtrim(base64_encode($keyword), '='); } - private function decodeFilename($filename) { + /** + * @param $filename + * @return mixed + */ + private function decodeFilename($filename) + { return $filename; // return base64_decode($filename); } @@ -42,45 +59,67 @@ private function decodeFilename($filename) { /* * Return $FILE FULL PATH */ - private function getFilePath($keyword, $skip = false) { + /** + * @param $keyword + * @param bool $skip + * @return string + * @throws \Exception + */ + private function getFilePath($keyword, $skip = false) + { $path = $this->getPath(); $filename = $this->encodeFilename($keyword); - $folder = substr($filename,0,2); - $path = rtrim($path,"/")."/".$folder; + $folder = substr($filename, 0, 2); + $path = rtrim($path, "/") . "/" . $folder; /* * Skip Create Sub Folders; */ - if($skip == false) { + if ($skip == false) { //if it doesn't exist, I can't create it, and nobody beat me to creating it: - if(!@is_dir($path) && !@mkdir($path,$this->__setChmodAuto()) && !@is_dir($path)) { - throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92); + if (!@is_dir($path) && !@mkdir($path, + $this->__setChmodAuto()) && !@is_dir($path) + ) { + throw new Exception("PLEASE CHMOD " . $this->getPath() . " - 0777 OR ANY WRITABLE PERMISSION!", + 92); } //if it does exist (after someone beat me to it, perhaps), but isn't writable or fixable: - if(@is_dir($path) && !is_writeable($path) && !@chmod($path,$this->__setChmodAuto())) { - throw new Exception("PLEASE CHMOD ".$this->getPath()." - 0777 OR ANY WRITABLE PERMISSION!",92); + if (@is_dir($path) && !is_writeable($path) && !@chmod($path, + $this->__setChmodAuto()) + ) { + throw new Exception("PLEASE CHMOD " . $this->getPath() . " - 0777 OR ANY WRITABLE PERMISSION!", + 92); } } - $file_path = $path."/".$filename.".txt"; + $file_path = $path . "/" . $filename . ".txt"; return $file_path; } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + * @throws \Exception + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { $file_path = $this->getFilePath($keyword); $tmp_path = $file_path . ".tmp"; - // echo "
DEBUG SET: ".$keyword." - ".$value." - ".$time."
"; + // echo "
DEBUG SET: ".$keyword." - ".$value." - ".$time."
"; $data = $this->encode($value); $toWrite = true; /* * Skip if Existing Caching in Options */ - if(isset($option['skipExisting']) && $option['skipExisting'] == true && @file_exists($file_path)) { + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true && @file_exists($file_path)) { $content = $this->readfile($file_path); $old = $this->decode($content); $toWrite = false; - if($this->isExpired($old)) { + if ($this->isExpired($old)) { $toWrite = true; } } @@ -91,39 +130,46 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) { * because first-to-lock wins and the file will exist before the writer attempts * to write. */ - if($toWrite == true && !@file_exists($tmp_path) && !@file_exists($file_path)) { - try { - $f = @fopen($tmp_path, "c"); - if ($f) { - if (flock($f,LOCK_EX| LOCK_NB)) { - $written = ($written && fwrite($f, $data)); - $written = ($written && fflush($f)); - $written = ($written && flock($f, LOCK_UN)); + if ($toWrite == true && !@file_exists($tmp_path) && !@file_exists($file_path)) { + try { + $f = @fopen($tmp_path, "c"); + if ($f) { + if (flock($f, LOCK_EX | LOCK_NB)) { + $written = ($written && fwrite($f, $data)); + $written = ($written && fflush($f)); + $written = ($written && flock($f, LOCK_UN)); } else { //arguably the file is being written to so the job is done - $written = false; + $written = false; } - $written = ($written && @fclose($f)); - $written = ($written && @rename($tmp_path,$file_path)); - } - } catch (Exception $e) { - // miss cache - $written = false; + $written = ($written && @fclose($f)); + $written = ($written && @rename($tmp_path, $file_path)); } + } catch (Exception $e) { + // miss cache + $written = false; + } } return $written; } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + * @throws \Exception + */ + public function driver_get($keyword, $option = array()) + { $file_path = $this->getFilePath($keyword); - if(!@file_exists($file_path)) { + if (!@file_exists($file_path)) { return null; } $content = $this->readfile($file_path); $object = $this->decode($content); - if($this->isExpired($object)) { + if ($this->isExpired($object)) { @unlink($file_path); $this->auto_clean_expired(); return null; @@ -132,9 +178,16 @@ function driver_get($keyword, $option = array()) { return $object; } - function driver_delete($keyword, $option = array()) { - $file_path = $this->getFilePath($keyword,true); - if(file_exists($file_path) && @unlink($file_path)) { + /** + * @param $keyword + * @param array $option + * @return bool + * @throws \Exception + */ + public function driver_delete($keyword, $option = array()) + { + $file_path = $this->getFilePath($keyword, true); + if (file_exists($file_path) && @unlink($file_path)) { return true; } else { return false; @@ -144,46 +197,55 @@ function driver_delete($keyword, $option = array()) { /* * Return total cache size + auto removed expired files */ - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + * @throws \Exception + */ + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => "", + "info" => "", + "size" => "", + "data" => "", ); $path = $this->getPath(); $dir = @opendir($path); - if(!$dir) { - throw new Exception("Can't read PATH:".$path,94); + if (!$dir) { + throw new Exception("Can't read PATH:" . $path, 94); } $total = 0; $removed = 0; $content = array(); - while($file=@readdir($dir)) { - if($file!="." && $file!=".." && is_dir($path."/".$file)) { + while ($file = @readdir($dir)) { + if ($file != "." && $file != ".." && is_dir($path . "/" . $file)) { // read sub dir - $subdir = @opendir($path."/".$file); - if(!$subdir) { - throw new Exception("Can't read path:".$path."/".$file,93); + $subdir = @opendir($path . "/" . $file); + if (!$subdir) { + throw new Exception("Can't read path:" . $path . "/" . $file, + 93); } - while($f = @readdir($subdir)) { - if($f!="." && $f!="..") { - $file_path = $path."/".$file."/".$f; + while ($f = @readdir($subdir)) { + if ($f != "." && $f != "..") { + $file_path = $path . "/" . $file . "/" . $f; $size = @filesize($file_path); $object = $this->decode($this->readfile($file_path)); - if(strpos($f,".") === false) { + if (strpos($f, ".") === false) { $key = $f; - } - else { + } else { //Because PHP 5.3, this cannot be written in single line $key = explode(".", $f); - $key = $key[0]; + $key = $key[ 0 ]; } - $content[$key] = array("size"=>$size,"write_time"=>$object["write_time"]); - if($this->isExpired($object)) { + $content[ $key ] = array( + "size" => $size, + "write_time" => $object[ "write_time" ], + ); + if ($this->isExpired($object)) { @unlink($file_path); $removed += $size; } @@ -191,45 +253,55 @@ function driver_stats($option = array()) { } } // end read subdir } // end if - } // end while - - $res['size'] = $total - $removed; - $res['info'] = array( - "Total [bytes]" => $total, - "Expired and removed [bytes]" => $removed, - "Current [bytes]" => $res['size'], - ); - $res["data"] = $content; - return $res; + } // end while + + $res[ 'size' ] = $total - $removed; + $res[ 'info' ] = array( + "Total [bytes]" => $total, + "Expired and removed [bytes]" => $removed, + "Current [bytes]" => $res[ 'size' ], + ); + $res[ "data" ] = $content; + return $res; } - function auto_clean_expired() { + /** + * + */ + public function auto_clean_expired() + { $autoclean = $this->get("keyword_clean_up_driver_files"); - if($autoclean == null) { - $this->set("keyword_clean_up_driver_files",3600*24); + if ($autoclean == null) { + $this->set("keyword_clean_up_driver_files", 3600 * 24); $res = $this->stats(); } } - function driver_clean($option = array()) { + /** + * @param array $option + * @throws \Exception + */ + public function driver_clean($option = array()) + { $path = $this->getPath(); $dir = @opendir($path); - if(!$dir) { - throw new Exception("Can't read PATH:".$path,94); + if (!$dir) { + throw new Exception("Can't read PATH:" . $path, 94); } - while($file=@readdir($dir)) { - if($file!="." && $file!=".." && is_dir($path."/".$file)) { + while ($file = @readdir($dir)) { + if ($file != "." && $file != ".." && is_dir($path . "/" . $file)) { // read sub dir - $subdir = @opendir($path."/".$file); - if(!$subdir) { - throw new Exception("Can't read path:".$path."/".$file,93); + $subdir = @opendir($path . "/" . $file); + if (!$subdir) { + throw new Exception("Can't read path:" . $path . "/" . $file, + 93); } - while($f = @readdir($subdir)) { - if($f!="." && $f!="..") { - $file_path = $path."/".$file."/".$f; + while ($f = @readdir($subdir)) { + if ($f != "." && $f != "..") { + $file_path = $path . "/" . $file . "/" . $f; @unlink($file_path); } } // end read subdir @@ -238,23 +310,31 @@ function driver_clean($option = array()) { } - function driver_isExisting($keyword) { - $file_path = $this->getFilePath($keyword,true); - if(!@file_exists($file_path)) { + /** + * @param $keyword + * @return bool + * @throws \Exception + */ + public function driver_isExisting($keyword) + { + $file_path = $this->getFilePath($keyword, true); + if (!@file_exists($file_path)) { return false; } else { // check expired or not $value = $this->get($keyword); - if($value == null) { - return false; - } else { - return true; - } + + return !($value == null); } } - function isExpired($object) { - if(isset($object['expired_time']) && time() >= $object['expired_time']) { + /** + * @param $object + * @return bool + */ + public function isExpired($object) + { + if (isset($object[ 'expired_time' ]) && time() >= $object[ 'expired_time' ]) { return true; } else { return false; diff --git a/phpfastcache/3.0.0/drivers/memcache.php b/phpfastcache/3.0.0/drivers/memcache.php index 585d30573..945af3491 100644 --- a/phpfastcache/3.0.0/drivers/memcache.php +++ b/phpfastcache/3.0.0/drivers/memcache.php @@ -1,59 +1,73 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ +class phpfastcache_memcache extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * @var \Memcache + */ + public $instant; + + /** + * phpfastcache_memcache constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + if (class_exists("Memcache")) { + $this->instant = new Memcache(); + } else { + $this->fallback = true; + } + } -class phpfastcache_memcache extends BasePhpFastCache implements phpfastcache_driver { - - var $instant; - - function checkdriver() { + /** + * @return bool + */ + public function checkdriver() + { // Check memcache - if(function_exists("memcache_connect")) { + if (function_exists("memcache_connect")) { return true; } - $this->fallback = true; + $this->fallback = true; return false; } - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - if(class_exists("Memcache")) { - $this->instant = new Memcache(); - } else { - $this->fallback = true; - } - - } - - function connectServer() { - $server = $this->config['memcache']; - if(count($server) < 1) { + /** + * + */ + public function connectServer() + { + $server = $this->config[ 'memcache' ]; + if (count($server) < 1) { $server = array( - array("127.0.0.1",11211), + array("127.0.0.1", 11211), ); } - foreach($server as $s) { - $name = $s[0]."_".$s[1]; - if(!isset($this->checked[$name])) { - try { - if(!$this->instant->addserver($s[0],$s[1])) { - $this->fallback = true; - } + foreach ($server as $s) { + $name = $s[ 0 ] . "_" . $s[ 1 ]; + if (!isset($this->checked[ $name ])) { + try { + if (!$this->instant->addserver($s[ 0 ], $s[ 1 ])) { + $this->fallback = true; + } - $this->checked[$name] = 1; - } catch(Exception $e) { - $this->fallback = true; - } + $this->checked[ $name ] = 1; + } catch (Exception $e) { + $this->fallback = true; + } } @@ -61,72 +75,103 @@ function connectServer() { } } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - $this->connectServer(); + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return array|bool + */ + public function driver_set( + $keyword, + $value = "", + $time = 300, + $option = array() + ) { + $this->connectServer(); - // Memcache will only allow a expiration timer less than 2592000 seconds, - // otherwise, it will assume you're giving it a UNIX timestamp. - if($time>2592000) { - $time = time()+$time; - } - - if(isset($option['skipExisting']) && $option['skipExisting'] == true) { - return $this->instant->add($keyword, $value, false, $time ); + // Memcache will only allow a expiration timer less than 2592000 seconds, + // otherwise, it will assume you're giving it a UNIX timestamp. + if ($time > 2592000) { + $time = time() + $time; + } + + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + return $this->instant->add($keyword, $value, false, $time); - } else { - return $this->instant->set($keyword, $value, false, $time ); - } + } else { + return $this->instant->set($keyword, $value, false, $time); + } } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return array|null|string + */ + public function driver_get($keyword, $option = array()) + { - $this->connectServer(); + $this->connectServer(); - // return null if no caching - // return value if in caching + // return null if no caching + // return value if in caching - $x = $this->instant->get($keyword); + $x = $this->instant->get($keyword); - if($x == false) { - return null; - } else { - return $x; - } + if ($x == false) { + return null; + } else { + return $x; + } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { $this->connectServer(); $this->instant->delete($keyword); } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $this->connectServer(); $res = array( - "info" => "", - "size" => "", - "data" => $this->instant->getStats(), + "info" => "", + "size" => "", + "data" => $this->instant->getStats(), ); return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + */ + public function driver_clean($option = array()) + { $this->connectServer(); $this->instant->flush(); } - function driver_isExisting($keyword) { + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { $this->connectServer(); $x = $this->get($keyword); - if($x == null) { - return false; - } else { - return true; - } - } - - + return !($x == null); + } } diff --git a/phpfastcache/3.0.0/drivers/memcached.php b/phpfastcache/3.0.0/drivers/memcached.php index 2946ee2db..7347a1270 100644 --- a/phpfastcache/3.0.0/drivers/memcached.php +++ b/phpfastcache/3.0.0/drivers/memcached.php @@ -1,86 +1,113 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ +class phpfastcache_memcached extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * @var \Memcached + */ + public $instant; + + /** + * phpfastcache_memcached constructor. + * @param array $config + */ + public function __construct($config = array()) + { + + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + if (class_exists("Memcached")) { + $this->instant = new Memcached(); + } else { + $this->fallback = true; + } -class phpfastcache_memcached extends BasePhpFastCache implements phpfastcache_driver { - - var $instant; + } - function checkdriver() { - if(class_exists("Memcached")) { + /** + * @return bool + */ + public function checkdriver() + { + if (class_exists("Memcached")) { return true; } - $this->fallback = true; - return false; + $this->fallback = true; + return false; } - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - if(class_exists("Memcached")) { - $this->instant = new Memcached(); - } else { - $this->fallback = true; - } + /** + * @return bool + */ + public function connectServer() + { - } - - function connectServer() { - - if($this->checkdriver() == false) { - return false; - } + if ($this->checkdriver() == false) { + return false; + } - $s = $this->config['memcache']; - if(count($s) < 1) { + $s = $this->config[ 'memcache' ]; + if (count($s) < 1) { $s = array( - array("127.0.0.1",11211,100), + array("127.0.0.1", 11211, 100), ); } - foreach($s as $server) { - $name = isset($server[0]) ? $server[0] : "127.0.0.1"; - $port = isset($server[1]) ? $server[1] : 11211; - $sharing = isset($server[2]) ? $server[2] : 0; - $checked = $name."_".$port; - if(!isset($this->checked[$checked])) { - try { - if($sharing >0 ) { - if(!$this->instant->addServer($name,$port,$sharing)) { - $this->fallback = true; - } - } else { - - if(!$this->instant->addServer($name,$port)) { - $this->fallback = true; - } - } - $this->checked[$checked] = 1; - } catch (Exception $e) { - $this->fallback = true; - } + foreach ($s as $server) { + $name = isset($server[ 0 ]) ? $server[ 0 ] : "127.0.0.1"; + $port = isset($server[ 1 ]) ? $server[ 1 ] : 11211; + $sharing = isset($server[ 2 ]) ? $server[ 2 ] : 0; + $checked = $name . "_" . $port; + if (!isset($this->checked[ $checked ])) { + try { + if ($sharing > 0) { + if (!$this->instant->addServer($name, $port, + $sharing) + ) { + $this->fallback = true; + } + } else { + + if (!$this->instant->addServer($name, $port)) { + $this->fallback = true; + } + } + $this->checked[ $checked ] = 1; + } catch (Exception $e) { + $this->fallback = true; + } } } } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { $this->connectServer(); // Memcache will only allow a expiration timer less than 2592000 seconds, // otherwise, it will assume you're giving it a UNIX timestamp. - if($time>2592000) { - $time = time()+$time; + if ($time > 2592000) { + $time = time() + $time; } - if(isset($option['isExisting']) && $option['isExisting'] == true) { + if (isset($option[ 'isExisting' ]) && $option[ 'isExisting' ] == true) { return $this->instant->add($keyword, $value, $time); } else { return $this->instant->set($keyword, $value, $time); @@ -88,49 +115,68 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) { } } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching $this->connectServer(); $x = $this->instant->get($keyword); - if($x == false) { + if ($x == false) { return null; } else { return $x; } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { $this->connectServer(); $this->instant->delete($keyword); } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $this->connectServer(); $res = array( - "info" => "", - "size" => "", - "data" => $this->instant->getStats(), + "info" => "", + "size" => "", + "data" => $this->instant->getStats(), ); return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + */ + public function driver_clean($option = array()) + { $this->connectServer(); $this->instant->flush(); } - function driver_isExisting($keyword) { + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { $this->connectServer(); $x = $this->get($keyword); - if($x == null) { - return false; - } else { - return true; - } - } - - + return !($x == null); + } } diff --git a/phpfastcache/3.0.0/drivers/predis.php b/phpfastcache/3.0.0/drivers/predis.php index e8369e90f..9dd935a28 100644 --- a/phpfastcache/3.0.0/drivers/predis.php +++ b/phpfastcache/3.0.0/drivers/predis.php @@ -1,168 +1,206 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com - * - * Redis Extension with: - * http://pecl.php.net/package/redis */ +class phpfastcache_predis extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * @var bool + */ + public $checked_redis = false; + + /** + * phpfastcache_predis constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!class_exists("\\Predis\\Client")) { + $this->required_extension("predis-1.0/autoload.php"); + } + } - -class phpfastcache_predis extends BasePhpFastCache implements phpfastcache_driver { - - var $checked_redis = false; - - function checkdriver() { + /** + * @return bool + */ + public function checkdriver() + { // Check memcache - if (! class_exists("\\Predis\\Client")) { - $this->required_extension("predis-1.0/autoload.php"); - try { - Predis\Autoloader::register(); - } catch(Exception $e) { + if (!class_exists("\\Predis\\Client")) { + $this->required_extension("predis-1.0/autoload.php"); + try { + Predis\Autoloader::register(); + } catch (Exception $e) { - } + } } return true; } - function __construct($config = array()) { - $this->setup($config); - if (! class_exists("\\Predis\\Client")) { - $this->required_extension("predis-1.0/autoload.php"); - } - } - - function connectServer() { - - $server = isset($this->config['redis']) ? $this->config['redis'] : array( - "host" => "127.0.0.1", - "port" => "6379", - "password" => "", - "database" => "" - ); - - - if($this->checked_redis === false) { - $c = array( - "host" => $server['host'], - ); - - $port = isset($server['port']) ? $server['port'] : ""; - if($port!="") { - $c['port'] = $port; - } - $password = isset($server['password']) ? $server['password'] : ""; - if($password!="") { - $c['password'] = $password; - } - - $database = isset($server['database']) ? $server['database'] : ""; - if($database!="") { - $c['database'] = $database; - } - - $timeout = isset($server['timeout']) ? $server['timeout'] : ""; - if($timeout!="") { - $c['timeout'] = $timeout; - } - - $read_write_timeout = isset($server['read_write_timeout']) ? $server['read_write_timeout'] : ""; - if($read_write_timeout!="") { - $c['read_write_timeout'] = $read_write_timeout; - } - - $this->instant = new Predis\Client($c); - - $this->checked_redis = true; - - if(!$this->instant) { - $this->fallback = true; - return false; - } else { - return true; - } - } + /** + * @return bool + */ + public function connectServer() + { + + $server = isset($this->config[ 'redis' ]) ? $this->config[ 'redis' ] : array( + "host" => "127.0.0.1", + "port" => "6379", + "password" => "", + "database" => "", + ); + + + if ($this->checked_redis === false) { + $c = array( + "host" => $server[ 'host' ], + ); + + $port = isset($server[ 'port' ]) ? $server[ 'port' ] : ""; + if ($port != "") { + $c[ 'port' ] = $port; + } + + $password = isset($server[ 'password' ]) ? $server[ 'password' ] : ""; + if ($password != "") { + $c[ 'password' ] = $password; + } + + $database = isset($server[ 'database' ]) ? $server[ 'database' ] : ""; + if ($database != "") { + $c[ 'database' ] = $database; + } + + $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : ""; + if ($timeout != "") { + $c[ 'timeout' ] = $timeout; + } + + $read_write_timeout = isset($server[ 'read_write_timeout' ]) ? $server[ 'read_write_timeout' ] : ""; + if ($read_write_timeout != "") { + $c[ 'read_write_timeout' ] = $read_write_timeout; + } + + $this->instant = new Predis\Client($c); + + $this->checked_redis = true; + + if (!$this->instant) { + $this->fallback = true; + return false; + } else { + return true; + } + } - return true; + return true; } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - if($this->connectServer()) { - $value = $this->encode($value); - if (isset($option['skipExisting']) && $option['skipExisting'] == true) { - return $this->instant->setex($keyword, $time, $value); - } else { - return $this->instant->setex($keyword, $time, $value ); - } + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return mixed + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + if ($this->connectServer()) { + $value = $this->encode($value); + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + return $this->instant->setex($keyword, $time, $value); + } else { + return $this->instant->setex($keyword, $time, $value); + } } else { - return $this->backup()->set($keyword, $value, $time, $option); + return $this->backup()->set($keyword, $value, $time, $option); } } - function driver_get($keyword, $option = array()) { - if($this->connectServer()) { - // return null if no caching - // return value if in caching' - $x = $this->instant->get($keyword); - if($x == false) { - return null; - } else { - - return $this->decode($x); - } + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { + if ($this->connectServer()) { + // return null if no caching + // return value if in caching' + $x = $this->instant->get($keyword); + if ($x == false) { + return null; + } else { + + return $this->decode($x); + } } else { - $this->backup()->get($keyword, $option); + $this->backup()->get($keyword, $option); } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { - if($this->connectServer()) { - $this->instant->del($keyword); + if ($this->connectServer()) { + $this->instant->del($keyword); } } - function driver_stats($option = array()) { - if($this->connectServer()) { - $res = array( - "info" => "", - "size" => "", - "data" => $this->instant->info(), - ); - - return $res; + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { + if ($this->connectServer()) { + $res = array( + "info" => "", + "size" => "", + "data" => $this->instant->info(), + ); + + return $res; } - return array(); + return array(); } - function driver_clean($option = array()) { - if($this->connectServer()) { - $this->instant->flushDB(); + /** + * @param array $option + */ + public function driver_clean($option = array()) + { + if ($this->connectServer()) { + $this->instant->flushDB(); } } - function driver_isExisting($keyword) { - if($this->connectServer()) { - $x = $this->instant->exists($keyword); - if($x == null) { - return false; - } else { - return true; - } + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + if ($this->connectServer()) { + $x = $this->instant->exists($keyword); + return !($x == null); } else { - return $this->backup()->isExisting($keyword); + return $this->backup()->isExisting($keyword); } - } - - - } diff --git a/phpfastcache/3.0.0/drivers/redis.php b/phpfastcache/3.0.0/drivers/redis.php index 75b9c2e9c..21f4911ed 100644 --- a/phpfastcache/3.0.0/drivers/redis.php +++ b/phpfastcache/3.0.0/drivers/redis.php @@ -1,170 +1,213 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com - * - * Redis Extension with: - * http://pecl.php.net/package/redis */ +class phpfastcache_predis extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * @var bool + */ + public $checked_redis = false; + + /** + * phpfastcache_predis constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + if (class_exists("Redis")) { + $this->instant = new Redis(); + } + } -class phpfastcache_redis extends BasePhpFastCache implements phpfastcache_driver { - - var $checked_redis = false; - - function checkdriver() { + /** + * @return bool + */ + public function checkdriver() + { // Check memcache - if(class_exists("Redis")) { + if (class_exists("Redis")) { return true; } - $this->fallback = true; + $this->fallback = true; return false; } - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - if(class_exists("Redis")) { - $this->instant = new Redis(); - } - } + /** + * @return bool + */ + public function connectServer() + { + + $server = isset($this->config[ 'redis' ]) ? $this->config[ 'redis' ] : array( + "host" => "127.0.0.1", + "port" => "6379", + "password" => "", + "database" => "", + "timeout" => "1", + ); + + if ($this->checked_redis === false) { + + $host = $server[ 'host' ]; + + $port = isset($server[ 'port' ]) ? (Int)$server[ 'port' ] : ""; + if ($port != "") { + $c[ 'port' ] = $port; + } + + $password = isset($server[ 'password' ]) ? $server[ 'password' ] : ""; + if ($password != "") { + $c[ 'password' ] = $password; + } + + $database = isset($server[ 'database' ]) ? $server[ 'database' ] : ""; + if ($database != "") { + $c[ 'database' ] = $database; + } + + $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : ""; + if ($timeout != "") { + $c[ 'timeout' ] = $timeout; + } + + $read_write_timeout = isset($server[ 'read_write_timeout' ]) ? $server[ 'read_write_timeout' ] : ""; + if ($read_write_timeout != "") { + $c[ 'read_write_timeout' ] = $read_write_timeout; + } + + + if (!$this->instant->connect($host, (int)$port, (Int)$timeout)) { + $this->checked_redis = true; + $this->fallback = true; + return false; + } else { + if ($database != "") { + $this->instant->select((Int)$database); + } + $this->checked_redis = true; + return true; + } + } - function connectServer() { - - $server = isset($this->config['redis']) ? $this->config['redis'] : array( - "host" => "127.0.0.1", - "port" => "6379", - "password" => "", - "database" => "", - "timeout" => "1", - ); - - if($this->checked_redis === false) { - - $host = $server['host']; - - $port = isset($server['port']) ? (Int)$server['port'] : ""; - if($port!="") { - $c['port'] = $port; - } - - $password = isset($server['password']) ? $server['password'] : ""; - if($password!="") { - $c['password'] = $password; - } - - $database = isset($server['database']) ? $server['database'] : ""; - if($database!="") { - $c['database'] = $database; - } - - $timeout = isset($server['timeout']) ? $server['timeout'] : ""; - if($timeout!="") { - $c['timeout'] = $timeout; - } - - $read_write_timeout = isset($server['read_write_timeout']) ? $server['read_write_timeout'] : ""; - if($read_write_timeout!="") { - $c['read_write_timeout'] = $read_write_timeout; - } - - - - if(!$this->instant->connect($host,(int)$port,(Int)$timeout)) { - $this->checked_redis = true; - $this->fallback = true; - return false; - } else { - if($database!="") { - $this->instant->select((Int)$database); - } - $this->checked_redis = true; - return true; - } - } - - return true; + return true; } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - if($this->connectServer()) { - $value = $this->encode($value); - if (isset($option['skipExisting']) && $option['skipExisting'] == true) { - return $this->instant->set($keyword, $value, array('xx', 'ex' => $time)); - } else { - return $this->instant->set($keyword, $value, $time); - } + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + if ($this->connectServer()) { + $value = $this->encode($value); + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + return $this->instant->set($keyword, $value, + array('xx', 'ex' => $time)); + } else { + return $this->instant->set($keyword, $value, $time); + } } else { - return $this->backup()->set($keyword, $value, $time, $option); + return $this->backup()->set($keyword, $value, $time, $option); } } - function driver_get($keyword, $option = array()) { - if($this->connectServer()) { - // return null if no caching - // return value if in caching' - $x = $this->instant->get($keyword); - if($x == false) { - return null; - } else { - - return $this->decode($x); - } + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { + if ($this->connectServer()) { + // return null if no caching + // return value if in caching' + $x = $this->instant->get($keyword); + if ($x == false) { + return null; + } else { + + return $this->decode($x); + } } else { - $this->backup()->get($keyword, $option); + $this->backup()->get($keyword, $option); } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { - if($this->connectServer()) { - $this->instant->delete($keyword); + if ($this->connectServer()) { + $this->instant->delete($keyword); } } - function driver_stats($option = array()) { - if($this->connectServer()) { - $res = array( - "info" => "", - "size" => "", - "data" => $this->instant->info(), - ); - - return $res; + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { + if ($this->connectServer()) { + $res = array( + "info" => "", + "size" => "", + "data" => $this->instant->info(), + ); + + return $res; } - return array(); + return array(); } - function driver_clean($option = array()) { - if($this->connectServer()) { - $this->instant->flushDB(); + /** + * @param array $option + */ + public function driver_clean($option = array()) + { + if ($this->connectServer()) { + $this->instant->flushDB(); } } - function driver_isExisting($keyword) { - if($this->connectServer()) { - $x = $this->instant->exists($keyword); - if($x == null) { - return false; - } else { - return true; - } + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + if ($this->connectServer()) { + $x = $this->instant->exists($keyword); + if ($x == null) { + return false; + } else { + return true; + } } else { - return $this->backup()->isExisting($keyword); + return $this->backup()->isExisting($keyword); } } - - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/sqlite.php b/phpfastcache/3.0.0/drivers/sqlite.php index a55d4eeac..57eea25e7 100644 --- a/phpfastcache/3.0.0/drivers/sqlite.php +++ b/phpfastcache/3.0.0/drivers/sqlite.php @@ -1,28 +1,75 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ - - -class phpfastcache_sqlite extends BasePhpFastCache implements phpfastcache_driver { +class phpfastcache_sqlite extends BasePhpFastCache implements phpfastcache_driver +{ + /** + * + */ const SQLITE_DIR = 'sqlite'; + /** + * + */ const INDEXING_FILE = 'indexing'; - var $max_size = 10; // 10 mb + /** + * @var int + */ + public $max_size = 10; // 10 mb + + /** + * @var array + */ + public $instant = array(); + /** + * @var null + */ + public $indexing = null; + /** + * @var string + */ + public $path = ""; - var $instant = array(); - var $indexing = NULL; - var $path = ""; + /** + * @var int + */ + public $currentDB = 1; + + /** + * Init Main Database & Sub Database + * phpfastcache_sqlite constructor. + * @param array $config + */ + public function __construct($config = array()) + { + /** + * init the path + */ + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } - var $currentDB = 1; + if (!file_exists($this->getPath() . "/" . self::SQLITE_DIR)) { + if (!mkdir($this->getPath() . "/" . self::SQLITE_DIR, + $this->__setChmodAuto()) + ) { + $this->fallback = true; + } + } + $this->path = $this->getPath() . "/" . self::SQLITE_DIR; + } - /* + /** * INIT NEW DB + * @param \PDO $db */ - function initDB(PDO $db) { + public function initDB(PDO $db) + { $db->exec('drop table if exists "caching"'); $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); @@ -30,16 +77,18 @@ function initDB(PDO $db) { $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); } - /* + /** * INIT Indexing DB + * @param \PDO $db */ - function initIndexing(PDO $db) { + public function initIndexing(PDO $db) + { // delete everything before reset indexing $dir = @opendir($this->path); - while($file = @readdir($dir)) { - if($file!="." && $file!=".." && $file!=self::INDEXING_FILE && $file!="dbfastcache") { - @unlink($this->path."/".$file); + while ($file = @readdir($dir)) { + if ($file != "." && $file != ".." && $file != self::INDEXING_FILE && $file != "dbfastcache") { + @unlink($this->path . "/" . $file); } } @@ -50,22 +99,25 @@ function initIndexing(PDO $db) { } - /* + /** * INIT Instant DB * Return Database of Keyword + * @param $keyword + * @return int */ - function indexing($keyword) { - if($this->indexing == NULL) { + public function indexing($keyword) + { + if ($this->indexing == null) { $createTable = false; - if(!@file_exists($this->path."/".self::INDEXING_FILE)) { + if (!@file_exists($this->path . "/" . self::INDEXING_FILE)) { $createTable = true; } - $PDO = new PDO("sqlite:".$this->path."/".self::INDEXING_FILE); + $PDO = new PDO("sqlite:" . $this->path . "/" . self::INDEXING_FILE); $PDO->setAttribute(PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION); + PDO::ERRMODE_EXCEPTION); - if($createTable == true) { + if ($createTable == true) { $this->initIndexing($PDO); } $this->indexing = $PDO; @@ -74,21 +126,21 @@ function indexing($keyword) { $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); $stm->execute(); $row = $stm->fetch(PDO::FETCH_ASSOC); - if(!isset($row['db'])) { + if (!isset($row[ 'db' ])) { $db = 1; - } elseif($row['db'] <=1 ) { + } elseif ($row[ 'db' ] <= 1) { $db = 1; } else { - $db = $row['db']; + $db = $row[ 'db' ]; } // check file size - $size = @file_exists($this->path."/db".$db) ? @filesize($this->path."/db".$db) : 1; - $size = round($size / 1024 / 1024,1); + $size = @file_exists($this->path . "/db" . $db) ? @filesize($this->path . "/db" . $db) : 1; + $size = round($size / 1024 / 1024, 1); - if($size > $this->max_size) { + if ($size > $this->max_size) { $db = $db + 1; } $this->currentDB = $db; @@ -98,11 +150,11 @@ function indexing($keyword) { // look for keyword $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); $stm->execute(array( - ":keyword" => $keyword + ":keyword" => $keyword, )); $row = $stm->fetch(PDO::FETCH_ASSOC); - if(isset($row['db']) && $row['db'] != "") { - $db = $row['db']; + if (isset($row[ 'db' ]) && $row[ 'db' ] != "") { + $db = $row[ 'db' ]; } else { /* * Insert new to Indexing @@ -110,15 +162,21 @@ function indexing($keyword) { $db = $this->currentDB; $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); $stm->execute(array( - ":keyword" => $keyword, - ":db" => $db, + ":keyword" => $keyword, + ":db" => $db, )); } return $db; } - function db($keyword, $reset = false) { + /** + * @param $keyword + * @param bool $reset + * @return mixed + */ + public function db($keyword, $reset = false) + { /* * Default is fastcache */ @@ -127,90 +185,88 @@ function db($keyword, $reset = false) { /* * init instant */ - if(!isset($this->instant[$instant])) { + if (!isset($this->instant[ $instant ])) { // check DB Files ready or not $createTable = false; - if(!@file_exists($this->path."/db".$instant) || $reset == true) { + if (!@file_exists($this->path . "/db" . $instant) || $reset == true) { $createTable = true; } - $PDO = new PDO("sqlite:".$this->path."/db".$instant); + $PDO = new PDO("sqlite:" . $this->path . "/db" . $instant); $PDO->setAttribute(PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION); + PDO::ERRMODE_EXCEPTION); - if($createTable == true) { + if ($createTable == true) { $this->initDB($PDO); } - $this->instant[$instant] = $PDO; + $this->instant[ $instant ] = $PDO; unset($PDO); } - return $this->instant[$instant]; + return $this->instant[ $instant ]; } - function checkdriver() { - if(extension_loaded('pdo_sqlite') && is_writeable($this->getPath())) { - return true; + /** + * @return bool + */ + public function checkdriver() + { + if (extension_loaded('pdo_sqlite') && is_writeable($this->getPath())) { + return true; } $this->fallback = true; return false; } - /* - * Init Main Database & Sub Database - */ - function __construct($config = array()) { - /* - * init the path - */ - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - if(!@file_exists($this->getPath()."/".self::SQLITE_DIR)) { - if(!@mkdir($this->getPath()."/".self::SQLITE_DIR,$this->__setChmodAuto())) { - $this->fallback = true; - } - } - $this->path = $this->getPath()."/".self::SQLITE_DIR; - } - - - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - $skipExisting = isset($option['skipExisting']) ? $option['skipExisting'] : false; + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set( + $keyword, + $value = "", + $time = 300, + $option = array() + ) { + $skipExisting = isset($option[ 'skipExisting' ]) ? $option[ 'skipExisting' ] : false; $toWrite = true; // check in cache first - $in_cache = $this->get($keyword,$option); + $in_cache = $this->get($keyword, $option); - if($skipExisting == true) { - if($in_cache == null) { + if ($skipExisting == true) { + if ($in_cache == null) { $toWrite = true; } else { $toWrite = false; } } - if($toWrite == true) { + if ($toWrite == true) { try { - $stm = $this->db($keyword)->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); + $stm = $this->db($keyword) + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); $stm->execute(array( - ":keyword" => $keyword, - ":object" => $this->encode($value), - ":exp" => time() + (Int)$time, + ":keyword" => $keyword, + ":object" => $this->encode($value), + ":exp" => time() + (Int)$time, )); return true; - } catch(PDOException $e) { + } catch (PDOException $e) { try { - $stm = $this->db($keyword,true)->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); + $stm = $this->db($keyword, true) + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); $stm->execute(array( - ":keyword" => $keyword, - ":object" => $this->encode($value), - ":exp" => time() + (Int)$time, + ":keyword" => $keyword, + ":object" => $this->encode($value), + ":exp" => time() + (Int)$time, )); } catch (PDOException $e) { return false; @@ -225,68 +281,94 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) { } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching try { - $stm = $this->db($keyword)->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm = $this->db($keyword) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); $stm->execute(array( - ":keyword" => $keyword + ":keyword" => $keyword, )); $row = $stm->fetch(PDO::FETCH_ASSOC); - } catch(PDOException $e) { + } catch (PDOException $e) { try { - $stm = $this->db($keyword,true)->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm = $this->db($keyword, true) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); $stm->execute(array( - ":keyword" => $keyword + ":keyword" => $keyword, )); $row = $stm->fetch(PDO::FETCH_ASSOC); - } catch(PDOException $e) { + } catch (PDOException $e) { return null; } } - if($this->isExpired($row)) { + if ($this->isExpired($row)) { $this->deleteRow($row); return null; } - if(isset($row['id'])) { - $data = $this->decode($row['object']); + if (isset($row[ 'id' ])) { + $data = $this->decode($row[ 'object' ]); return $data; } return null; } - function isExpired($row) { - if(isset($row['exp']) && time() >= $row['exp']) { + /** + * @param $row + * @return bool + */ + public function isExpired($row) + { + if (isset($row[ 'exp' ]) && time() >= $row[ 'exp' ]) { return true; } return false; } - function deleteRow($row) { + /** + * @param $row + * @return bool + */ + public function deleteRow($row) + { try { - $stm = $this->db($row['keyword'])->prepare("DELETE FROM `caching` WHERE (`id`=:id) OR (`exp` <= :U) "); + $stm = $this->db($row[ 'keyword' ]) + ->prepare("DELETE FROM `caching` WHERE (`id`=:id) OR (`exp` <= :U) "); $stm->execute(array( - ":id" => $row['id'], - ":U" => time(), + ":id" => $row[ 'id' ], + ":U" => time(), )); } catch (PDOException $e) { return false; } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return bool + */ + public function driver_delete($keyword, $option = array()) + { try { - $stm = $this->db($keyword)->prepare("DELETE FROM `caching` WHERE (`keyword`=:keyword) OR (`exp` <= :U)"); + $stm = $this->db($keyword) + ->prepare("DELETE FROM `caching` WHERE (`keyword`=:keyword) OR (`exp` <= :U)"); $stm->execute(array( - ":keyword" => $keyword, - ":U" => time(), + ":keyword" => $keyword, + ":U" => time(), )); } catch (PDOException $e) { return false; @@ -295,76 +377,90 @@ function driver_delete($keyword, $option = array()) { } - /* + /** * Return total cache size + auto removed expired entries + * @param array $option + * @return array */ - function driver_stats($option = array()) { + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => "", + "info" => "", + "size" => "", + "data" => "", ); $total = 0; $optimized = 0; $dir = @opendir($this->path); - while($file = @readdir($dir)) { - if($file!="." && $file!="..") { - $file_path = $this->path."/".$file; + while ($file = @readdir($dir)) { + if ($file != "." && $file != "..") { + $file_path = $this->path . "/" . $file; $size = @filesize($file_path); $total += $size; - if ($file!=self::INDEXING_FILE) { + if ($file != self::INDEXING_FILE) { try { - $PDO = new PDO("sqlite:".$file_path); + $PDO = new PDO("sqlite:" . $file_path); $PDO->setAttribute(PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION); + PDO::ERRMODE_EXCEPTION); $stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U"); $stm->execute(array( - ":U" => time(), + ":U" => time(), )); $PDO->exec("VACUUM;"); $size = @filesize($file_path); } catch (PDOException $e) { - $res['data'] .= sprintf("%s: %s\n", $file_path, $e->getMessage()); + $res[ 'data' ] .= sprintf("%s: %s\n", $file_path, + $e->getMessage()); } } $optimized += $size; } } - $res['size'] = $optimized; - $res['info'] = array( - "total before removing expired entries [bytes]" => $total, - "optimized after removing expired entries [bytes]" => $optimized, + $res[ 'size' ] = $optimized; + $res[ 'info' ] = array( + "total before removing expired entries [bytes]" => $total, + "optimized after removing expired entries [bytes]" => $optimized, ); return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + */ + public function driver_clean($option = array()) + { // close connection $this->instant = array(); - $this->indexing = NULL; + $this->indexing = null; // delete everything $dir = @opendir($this->path); - while($file = @readdir($dir)) { - if($file != "." && $file!="..") { - @unlink($this->path."/".$file); + while ($file = @readdir($dir)) { + if ($file != "." && $file != "..") { + @unlink($this->path . "/" . $file); } } } - function driver_isExisting($keyword) { + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { try { - $stm = $this->db($keyword)->prepare("SELECT COUNT(`id`) as `total` FROM `caching` WHERE `keyword`=:keyword"); + $stm = $this->db($keyword) + ->prepare("SELECT COUNT(`id`) as `total` FROM `caching` WHERE `keyword`=:keyword"); $stm->execute(array( - ":keyword" => $keyword + ":keyword" => $keyword, )); $data = $stm->fetch(PDO::FETCH_ASSOC); - if($data['total'] >= 1) { + if ($data[ 'total' ] >= 1) { return true; } else { return false; diff --git a/phpfastcache/3.0.0/drivers/ssdb.php b/phpfastcache/3.0.0/drivers/ssdb.php index 7aec1403a..fd82d656e 100644 --- a/phpfastcache/3.0.0/drivers/ssdb.php +++ b/phpfastcache/3.0.0/drivers/ssdb.php @@ -1,19 +1,38 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com - * + * * ssdb official website: * http://ssdb.io/ */ +class phpfastcache_ssdb extends BasePhpFastCache implements phpfastcache_driver +{ -class phpfastcache_ssdb extends BasePhpFastCache implements phpfastcache_driver { - + /** + * @var bool + */ private $checked_ssdb = false; - function checkdriver() { + /** + * phpfastcache_ssdb constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } + } + + /** + * @return bool + */ + public function checkdriver() + { // Check memcache $this->required_extension("SSDB.php"); if (class_exists("SimpleSSDB")) { @@ -23,27 +42,25 @@ function checkdriver() { return false; } - function __construct($config = array()) { - $this->setup($config); - if (!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - } - function connectServer() { + /** + * @return bool + */ + public function connectServer() + { - $server = isset($this->config['ssdb']) ? $this->config['ssdb'] : array( - "host" => "127.0.0.1", - "port" => 8888, - "password" => "", - "timeout" => 2000, - ); + $server = isset($this->config[ 'ssdb' ]) ? $this->config[ 'ssdb' ] : array( + "host" => "127.0.0.1", + "port" => 8888, + "password" => "", + "timeout" => 2000, + ); if ($this->checked_ssdb === false) { - $host = $server['host']; - $port = isset($server['port']) ? (Int) $server['port'] : 8888; - $password = isset($server['password']) ? $server['password'] : ""; - $timeout = isset($server['timeout']) ? (Int) $server['timeout'] : 2000; + $host = $server[ 'host' ]; + $port = isset($server[ 'port' ]) ? (Int)$server[ 'port' ] : 8888; + $password = isset($server[ 'password' ]) ? $server[ 'password' ] : ""; + $timeout = isset($server[ 'timeout' ]) ? (Int)$server[ 'timeout' ] : 2000; $this->instant = new SimpleSSDB($host, $port, $timeout); if (!empty($password)) { $this->instant->auth($password); @@ -60,50 +77,74 @@ function connectServer() { return true; } - function driver_set($keyword, $value = "", $time = 300, $option = array()) { + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { if ($this->connectServer()) { - if (isset($option['skipExisting']) && $option['skipExisting'] == true) { - $x = $this->instant->get($keyword); - if($x === false) { + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + $x = $this->instant->get($keyword); + if ($x === false) { return false; - }elseif(!is_null($x)) { + } elseif (!is_null($x)) { return true; } - } + } $value = $this->encode($value); - return $this->instant->setx($keyword, $value, $time); + return $this->instant->setx($keyword, $value, $time); } else { return $this->backup()->set($keyword, $value, $time, $option); } } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { if ($this->connectServer()) { // return null if no caching - // return value if in caching' - $x = $this->instant->get($keyword); - if($x == false) { - return null; - } else { - return $this->decode($x); - } + // return value if in caching' + $x = $this->instant->get($keyword); + if ($x == false) { + return null; + } else { + return $this->decode($x); + } } else { $this->backup()->get($keyword, $option); } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + */ + public function driver_delete($keyword, $option = array()) + { if ($this->connectServer()) { $this->instant->del($keyword); } } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { if ($this->connectServer()) { $res = array( - "info" => "", - "size" => $this->instant->dbsize(), - "data" => $this->instant->info(), + "info" => "", + "size" => $this->instant->dbsize(), + "data" => $this->instant->info(), ); return $res; @@ -112,24 +153,27 @@ function driver_stats($option = array()) { return array(); } - function driver_clean($option = array()) + /** + * @param array $option + * @return bool + */ + public function driver_clean($option = array()) { //Is not supported, only support command line operations return false; } - function driver_isExisting($keyword) + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) { if ($this->connectServer()) { $x = $this->instant->exists($keyword); - if ($x == null) { - return false; - } else { - return true; - } + return !($x == null); } else { return $this->backup()->isExisting($keyword); } } - } diff --git a/phpfastcache/3.0.0/drivers/wincache.php b/phpfastcache/3.0.0/drivers/wincache.php index 78c2c059a..62b2d87af 100644 --- a/phpfastcache/3.0.0/drivers/wincache.php +++ b/phpfastcache/3.0.0/drivers/wincache.php @@ -1,76 +1,118 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ +class phpfastcache_wincache extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * phpfastcache_wincache constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; + } -class phpfastcache_wincache extends BasePhpFastCache implements phpfastcache_driver { + } - function checkdriver() { - if(extension_loaded('wincache') && function_exists("wincache_ucache_set")) - { + /** + * @return bool + */ + public function checkdriver() + { + if (extension_loaded('wincache') && function_exists("wincache_ucache_set")) { return true; } - $this->fallback = true; + $this->fallback = true; return false; } - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; - } - - } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - if(isset($option['skipExisting']) && $option['skipExisting'] == true) { + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { return wincache_ucache_add($keyword, $value, $time); } else { return wincache_ucache_set($keyword, $value, $time); } } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching - $x = wincache_ucache_get($keyword,$suc); + $x = wincache_ucache_get($keyword, $suc); - if($suc == false) { + if ($suc == false) { return null; } else { return $x; } } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return bool + */ + public function driver_delete($keyword, $option = array()) + { return wincache_ucache_delete($keyword); } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => wincache_scache_info(), + "info" => "", + "size" => "", + "data" => wincache_scache_info(), ); return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + * @return bool + */ + public function driver_clean($option = array()) + { wincache_ucache_clear(); return true; } - function driver_isExisting($keyword) { - if(wincache_ucache_exists($keyword)) { + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + if (wincache_ucache_exists($keyword)) { return true; } else { return false; } } - - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/drivers/xcache.php b/phpfastcache/3.0.0/drivers/xcache.php index 4732bf9d9..1dfc30d59 100644 --- a/phpfastcache/3.0.0/drivers/xcache.php +++ b/phpfastcache/3.0.0/drivers/xcache.php @@ -1,89 +1,125 @@ http://www.phpfastcache.com * Example at our website, any bugs, problems, please visit http://faster.phpfastcache.com */ - -class phpfastcache_xcache extends BasePhpFastCache implements phpfastcache_driver { - - function checkdriver() { - // Check xcache - if(extension_loaded('xcache') && function_exists("xcache_get")) - { - return true; +class phpfastcache_xcache extends BasePhpFastCache implements phpfastcache_driver +{ + + /** + * phpfastcache_xcache constructor. + * @param array $config + */ + public function __construct($config = array()) + { + $this->setup($config); + if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { + $this->fallback = true; } - $this->fallback = true; - return false; } - function __construct($config = array()) { - $this->setup($config); - if(!$this->checkdriver() && !isset($config['skipError'])) { - $this->fallback = true; + /** + * @return bool + */ + public function checkdriver() + { + // Check xcache + if (extension_loaded('xcache') && function_exists("xcache_get")) { + return true; } + $this->fallback = true; + return false; } - function driver_set($keyword, $value = "", $time = 300, $option = array() ) { - - if(isset($option['skipExisting']) && $option['skipExisting'] == true) { - if(!$this->isExisting($keyword)) { - return xcache_set($keyword,serialize($value),$time); + /** + * @param $keyword + * @param string $value + * @param int $time + * @param array $option + * @return bool + */ + public function driver_set($keyword, $value = "", $time = 300, $option = array()) + { + + if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { + if (!$this->isExisting($keyword)) { + return xcache_set($keyword, serialize($value), $time); } } else { - return xcache_set($keyword,serialize($value),$time); + return xcache_set($keyword, serialize($value), $time); } return false; } - function driver_get($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return mixed|null + */ + public function driver_get($keyword, $option = array()) + { // return null if no caching // return value if in caching $data = unserialize(xcache_get($keyword)); - if($data === false || $data == "") { + if ($data === false || $data == "") { return null; } return $data; } - function driver_delete($keyword, $option = array()) { + /** + * @param $keyword + * @param array $option + * @return bool + */ + public function driver_delete($keyword, $option = array()) + { return xcache_unset($keyword); } - function driver_stats($option = array()) { + /** + * @param array $option + * @return array + */ + public function driver_stats($option = array()) + { $res = array( - "info" => "", - "size" => "", - "data" => "", + "info" => "", + "size" => "", + "data" => "", ); try { - $res['data'] = xcache_list(XC_TYPE_VAR,100); - } catch(Exception $e) { - $res['data'] = array(); + $res[ 'data' ] = xcache_list(XC_TYPE_VAR, 100); + } catch (Exception $e) { + $res[ 'data' ] = array(); } return $res; } - function driver_clean($option = array()) { + /** + * @param array $option + * @return bool + */ + public function driver_clean($option = array()) + { $cnt = xcache_count(XC_TYPE_VAR); - for ($i=0; $i < $cnt; $i++) { + for ($i = 0; $i < $cnt; $i++) { xcache_clear_cache(XC_TYPE_VAR, $i); } return true; } - function driver_isExisting($keyword) { - if(xcache_isset($keyword)) { - return true; - } else { - return false; - } + /** + * @param $keyword + * @return bool + */ + public function driver_isExisting($keyword) + { + return xcache_isset($keyword); } - - - } \ No newline at end of file diff --git a/phpfastcache/3.0.0/extensions.php b/phpfastcache/3.0.0/extensions.php index c76b8f7d1..c2fbe6816 100644 --- a/phpfastcache/3.0.0/extensions.php +++ b/phpfastcache/3.0.0/extensions.php @@ -1,7 +1,17 @@ http://www.phpfastcache.com + */ +abstract class phpfastcache_extensions +{ + /** + * @param $name + * @param $agr + */ + public function __call($name, $agr) + { } } \ No newline at end of file diff --git a/phpfastcache/3.0.0/phpfastcache.php b/phpfastcache/3.0.0/phpfastcache.php index 64f93197d..4829aedad 100644 --- a/phpfastcache/3.0.0/phpfastcache.php +++ b/phpfastcache/3.0.0/phpfastcache.php @@ -1,264 +1,350 @@ http://www.phpfastcache.com + */ -require_once(dirname(__FILE__)."/abstract.php"); -require_once(dirname(__FILE__)."/driver.php"); +require_once(dirname(__FILE__) . "/abstract.php"); +require_once(dirname(__FILE__) . "/driver.php"); -// short function -if(!function_exists("__c")) { - function __c($storage = "", $option = array()) { - return phpFastCache($storage, $option); - } +/** + * Short function + */ +if (!function_exists("__c")) { + /** + * @param string $storage + * @param array $option + * @return mixed + */ + function __c($storage = "", $option = array()) + { + return phpFastCache($storage, $option); + } } -// main function -if(!function_exists("phpFastCache")) { - function phpFastCache($storage = "auto", $config = array()) { +if (!function_exists("phpFastCache")) { + + /** + * Main function + * @param string $storage + * @param array $config + * @return mixed + */ + function phpFastCache($storage = "auto", $config = array()) + { $storage = strtolower($storage); - if(empty($config)) { + if (empty($config)) { $config = phpFastCache::$config; } - if($storage == "" || $storage == "auto") { + if ($storage == "" || $storage == "auto") { $storage = phpFastCache::getAutoClass($config); } - $instance = md5(json_encode($config).$storage); - if(!isset(phpFastCache_instances::$instances[$instance])) { - $class = "phpfastcache_".$storage; + $instance = md5(json_encode($config) . $storage); + if (!isset(phpFastCache_instances::$instances[ $instance ])) { + $class = "phpfastcache_" . $storage; phpFastCache::required($storage); - phpFastCache_instances::$instances[$instance] = new $class($config); - } + phpFastCache_instances::$instances[ $instance ] = new $class($config); + } - return phpFastCache_instances::$instances[$instance]; - } + return phpFastCache_instances::$instances[ $instance ]; + } } -class phpFastCache_instances { - public static $instances = array(); +/** + * Class phpFastCache_instances + */ +class phpFastCache_instances +{ + /** + * @var array + */ + public static $instances = array(); } -// main class -class phpFastCache { +/** + * Main class + * Class phpFastCache + */ +class phpFastCache +{ + /** + * @var bool + */ public static $disabled = false; - public static $config = array( - "storage" => "", // blank for auto - "default_chmod" => 0777, // 0777 , 0666, 0644 - /* - * Fall back when old driver is not support - */ - "fallback" => "files", - - "securityKey" => "auto", - "htaccess" => true, - "path" => "", - - "memcache" => array( - array("127.0.0.1",11211,1), - // array("new.host.ip",11211,1), - ), - - "redis" => array( - "host" => "127.0.0.1", - "port" => "", - "password" => "", - "database" => "", - "timeout" => "" - ), - - "ssdb" => array( - "host" => "127.0.0.1", - "port" => 8888, - "password" => "", - "timeout" => "" - ), - - "extensions" => array(), - ); + /** + * @var array + */ + public static $config = array( + "storage" => "", // blank for auto + "default_chmod" => 0777, // 0777 , 0666, 0644 + + "fallback" => "files", //Fall back when old driver is not support + + "securityKey" => "auto", + "htaccess" => true, + "path" => "", + + "memcache" => array( + array("127.0.0.1", 11211, 1), + // array("new.host.ip",11211,1), + ), + + "redis" => array( + "host" => "127.0.0.1", + "port" => "", + "password" => "", + "database" => "", + "timeout" => "", + ), + + "ssdb" => array( + "host" => "127.0.0.1", + "port" => 8888, + "password" => "", + "timeout" => "", + ), + + "extensions" => array(), + ); + + /** + * @var array + */ protected static $tmp = array(); - var $instance; - function __construct($storage = "", $config = array()) { - if(empty($config)) { + /** + * @var BasePhpFastCache $instance + */ + public $instance; + + /** + * phpFastCache constructor. + * @param string $storage + * @param array $config + */ + function __construct($storage = "", $config = array()) + { + if (empty($config)) { $config = phpFastCache::$config; } - $config['storage'] = $storage; + $config[ 'storage' ] = $storage; $storage = strtolower($storage); - if($storage == "" || $storage == "auto") { + if ($storage == "" || $storage == "auto") { $storage = self::getAutoClass($config); } - $this->instance = phpFastCache($storage,$config); + $this->instance = phpFastCache($storage, $config); } - - - - public function __call($name, $args) { + /** + * @param $name + * @param $args + * @return mixed + */ + public function __call($name, $args) + { return call_user_func_array(array($this->instance, $name), $args); } - - /* + /** * Cores */ - public static function getAutoClass($config) { - - $driver = "files"; - $path = self::getPath(false,$config); - if(is_writeable($path)) { + /** + * @param $config + * @return string + * @throws \Exception + */ + public static function getAutoClass($config) + { + $path = self::getPath(false, $config); + if (is_writable($path)) { $driver = "files"; - }else if(extension_loaded('apc') && ini_get('apc.enabled') && strpos(PHP_SAPI,"CGI") === false) { + } else if (extension_loaded('apc') && ini_get('apc.enabled') && strpos(PHP_SAPI, + "CGI") === false + ) { $driver = "apc"; - }else if(class_exists("memcached")) { + } else if (class_exists("memcached")) { $driver = "memcached"; - }elseif(extension_loaded('wincache') && function_exists("wincache_ucache_set")) { + } elseif (extension_loaded('wincache') && function_exists("wincache_ucache_set")) { $driver = "wincache"; - }elseif(extension_loaded('xcache') && function_exists("xcache_get")) { + } elseif (extension_loaded('xcache') && function_exists("xcache_get")) { $driver = "xcache"; - }else if(function_exists("memcache_connect")) { + } else if (function_exists("memcache_connect")) { $driver = "memcache"; - }else if(class_exists("Redis")) { + } else if (class_exists("Redis")) { $driver = "redis"; - }else { + } else { $driver = "files"; } - return $driver; - } - public static function getPath($skip_create_path = false, $config) { - if ( !isset($config['path']) || $config['path'] == '' ) - { + /** + * @param bool $skip_create_path + * @param $config + * @return string + * @throws \Exception + */ + public static function getPath($skip_create_path = false, $config) + { + if (!isset($config[ 'path' ]) || $config[ 'path' ] == '') { // revision 618 - if(self::isPHPModule()) { + if (self::isPHPModule()) { $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); $path = $tmp_dir; } else { - $path = isset($_SERVER['DOCUMENT_ROOT']) ? rtrim($_SERVER['DOCUMENT_ROOT'],"/")."/../" : rtrim(dirname(__FILE__),"/")."/"; + $path = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? rtrim($_SERVER[ 'DOCUMENT_ROOT' ], + "/") . "/../" : rtrim(dirname(__FILE__), "/") . "/"; } - if(self::$config['path'] != "") { - $path = $config['path']; + if (self::$config[ 'path' ] != "") { + $path = $config[ 'path' ]; } } else { - $path = $config['path']; + $path = $config[ 'path' ]; } - $securityKey = array_key_exists('securityKey',$config) ? $config['securityKey'] : ""; - if($securityKey == "" || $securityKey == "auto") { - $securityKey = self::$config['securityKey']; - if($securityKey == "auto" || $securityKey == "") { - $securityKey = isset($_SERVER['HTTP_HOST']) ? preg_replace('/^www./','',strtolower($_SERVER['HTTP_HOST'])) : "default"; + $securityKey = array_key_exists('securityKey', + $config) ? $config[ 'securityKey' ] : ""; + if ($securityKey == "" || $securityKey == "auto") { + $securityKey = self::$config[ 'securityKey' ]; + if ($securityKey == "auto" || $securityKey == "") { + $securityKey = isset($_SERVER[ 'HTTP_HOST' ]) ? preg_replace('/^www./', + '', strtolower($_SERVER[ 'HTTP_HOST' ])) : "default"; } } - if($securityKey != "") { - $securityKey.= "/"; + if ($securityKey != "") { + $securityKey .= "/"; } - + $securityKey = self::cleanFileName($securityKey); - $full_path = $path."/".$securityKey; + $full_path = $path . "/" . $securityKey; $full_pathx = md5($full_path); + if ($skip_create_path == false && !isset(self::$tmp[ $full_pathx ])) { - - if($skip_create_path == false && !isset(self::$tmp[$full_pathx])) { - - if(!@file_exists($full_path) || !@is_writable($full_path)) { - if(!@file_exists($full_path)) { - @mkdir($full_path,self::__setChmodAuto($config)); + if (!@file_exists($full_path) || !@is_writable($full_path)) { + if (!@file_exists($full_path)) { + @mkdir($full_path, self::__setChmodAuto($config)); } - if(!@is_writable($full_path)) { - @chmod($full_path,self::__setChmodAuto($config)); + if (!@is_writable($full_path)) { + @chmod($full_path, self::__setChmodAuto($config)); } - if(!@file_exists($full_path) || !@is_writable($full_path)) { - throw new Exception("PLEASE CREATE OR CHMOD ".$full_path." - 0777 OR ANY WRITABLE PERMISSION!",92); + if (!@file_exists($full_path) || !@is_writable($full_path)) { + throw new Exception("PLEASE CREATE OR CHMOD " . $full_path . " - 0777 OR ANY WRITABLE PERMISSION!", + 92); } } - self::$tmp[$full_pathx] = true; - self::htaccessGen($full_path, array_key_exists('htaccess',$config) ? $config['htaccess'] : false); + self::$tmp[ $full_pathx ] = true; + self::htaccessGen($full_path, array_key_exists('htaccess', + $config) ? $config[ 'htaccess' ] : false); } return realpath($full_path); } - - public static function cleanFileName($filename) { - $regex = array('/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/','/\.$/','/^\./'); - $replace = array('-','',''); - return preg_replace($regex,$replace,$filename); - } + /** + * @param $filename + * @return mixed + */ + public static function cleanFileName($filename) + { + $regex = array( + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', + '/\.$/', + '/^\./', + ); + $replace = array('-', '', ''); + return preg_replace($regex, $replace, $filename); + } - public static function __setChmodAuto($config) { - if(!isset($config['default_chmod']) || $config['default_chmod'] == "" || is_null($config['default_chmod'])) { + /** + * @param $config + * @return int + */ + public static function __setChmodAuto($config) + { + if (!isset($config[ 'default_chmod' ]) || $config[ 'default_chmod' ] == "" || is_null($config[ 'default_chmod' ])) { return 0777; } else { - return $config['default_chmod']; + return $config[ 'default_chmod' ]; } } - protected static function getOS() { + /** + * @return array + */ + protected static function getOS() + { $os = array( - "os" => PHP_OS, - "php" => PHP_SAPI, - "system" => php_uname(), - "unique" => md5(php_uname().PHP_OS.PHP_SAPI) + "os" => PHP_OS, + "php" => PHP_SAPI, + "system" => php_uname(), + "unique" => md5(php_uname() . PHP_OS . PHP_SAPI), ); return $os; } - public static function isPHPModule() { - if(PHP_SAPI == "apache2handler") { + /** + * @return bool + */ + public static function isPHPModule() + { + if (PHP_SAPI == "apache2handler") { return true; } else { - if(strpos(PHP_SAPI,"handler") !== false) { + if (strpos(PHP_SAPI, "handler") !== false) { return true; } } return false; } - protected static function htaccessGen($path, $create = true) { + /** + * @param $path + * @param bool $create + * @throws \Exception + */ + protected static function htaccessGen($path, $create = true) + { - if($create == true) { - if(!is_writeable($path)) { + if ($create == true) { + if (!is_writeable($path)) { try { - chmod($path,0777); - } - catch(Exception $e) { - throw new Exception("PLEASE CHMOD ".$path." - 0777 OR ANY WRITABLE PERMISSION!",92); + chmod($path, 0777); + } catch (Exception $e) { + throw new Exception("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!", + 92); } } - if(!@file_exists($path."/.htaccess")) { + if (!@file_exists($path . "/.htaccess")) { // echo "write me"; $html = "order deny, allow \r\n deny from all \r\n allow from 127.0.0.1"; - $f = @fopen($path."/.htaccess","w+"); - if(!$f) { - throw new Exception("PLEASE CHMOD ".$path." - 0777 OR ANY WRITABLE PERMISSION!",92); + $f = @fopen($path . "/.htaccess", "w+"); + if (!$f) { + throw new Exception("PLEASE CHMOD " . $path . " - 0777 OR ANY WRITABLE PERMISSION!", + 92); } - fwrite($f,$html); + fwrite($f, $html); fclose($f); @@ -267,18 +353,26 @@ protected static function htaccessGen($path, $create = true) { } - - public static function setup($name,$value = "") { - if(is_array($name)) { + /** + * @param $name + * @param string $value + */ + public static function setup($name, $value = "") + { + if (is_array($name)) { self::$config = $name; } else { - self::$config[$name] = $value; + self::$config[ $name ] = $value; } } - public static function debug($something) { + /** + * @param $something + */ + public static function debug($something) + { echo "Starting Debugging ...
\r\n "; - if(is_array($something)) { + if (is_array($something)) { echo "
";
             print_r($something);
             echo "
"; @@ -290,9 +384,11 @@ public static function debug($something) { exit; } - public static function required($class) { - require_once(dirname(__FILE__)."/drivers/".$class.".php"); + /** + * @param $class + */ + public static function required($class) + { + require_once(dirname(__FILE__) . "/drivers/" . $class . ".php"); } - - } diff --git a/phpfastcache/_extensions/regex.php b/phpfastcache/_extensions/regex.php index 27d0835e1..35bdabe50 100644 --- a/phpfastcache/_extensions/regex.php +++ b/phpfastcache/_extensions/regex.php @@ -1,9 +1,16 @@ http://www.phpfastcache.com */ class phpfastcache_ext_regex extends phpfastcache_extensions { - function delete($regx) { + + /** + * @param $regx + */ + public function delete($regx) { } } \ No newline at end of file