From 1ffaee07307650a986fd02ed7c4357b21a773e5b Mon Sep 17 00:00:00 2001 From: Wruczek Date: Sun, 29 Jan 2017 22:56:17 +0100 Subject: [PATCH] v 1.4.0 - Updated local libraries - PHP 7.1 support - New, proper caching method - Special cache folder --- .gitignore | 1 + api/status.php | 19 +- bans.php | 20 +- cache/.gitkeep | 0 cache/.htaccess | 3 + include/adminlist.php | 19 +- include/cacheutils.class.php | 49 + include/footer.php | 2 +- include/modulecheck.php | 25 +- lib/parsedown/parsedown.php | 14 +- lib/phpfastcache/LICENCE | 20 + .../bin/legacy/Psr/Cache/LICENSE.txt | 19 + .../bin/legacy/Psr/Cache/README.md | 9 + .../bin/legacy/Psr/Cache/composer.json | 25 + .../legacy/Psr/Cache/src/CacheException.php | 10 + .../Psr/Cache/src/CacheItemInterface.php | 106 +++ .../Psr/Cache/src/CacheItemPoolInterface.php | 139 +++ .../Cache/src/InvalidArgumentException.php | 13 + .../phpFastCache/CacheManager.php | 173 ---- .../phpFastCache/Core/DriverAbstract.php | 846 ------------------ .../phpFastCache/Core/DriverInterface.php | 86 -- .../phpFastCache/Core/phpFastCache.php | 354 -------- lib/phpfastcache/phpFastCache/Drivers/apc.php | 137 --- .../phpFastCache/Drivers/cookie.php | 156 ---- .../phpFastCache/Drivers/example.php | 128 --- .../phpFastCache/Drivers/files.php | 306 ------- .../phpFastCache/Drivers/memcache.php | 200 ----- .../phpFastCache/Drivers/memcached.php | 200 ----- .../phpFastCache/Drivers/mongodb.php | 125 --- .../phpFastCache/Drivers/predis.php | 222 ----- .../phpFastCache/Drivers/redis.php | 225 ----- .../phpFastCache/Drivers/sqlite.php | 482 ---------- .../phpFastCache/Drivers/ssdb.php | 191 ---- .../phpFastCache/Drivers/wincache.php | 133 --- .../phpFastCache/Drivers/xcache.php | 141 --- .../phpFastCache/Plugins/CronClearFiles.php | 33 - lib/phpfastcache/phpFastCache/Util/Legacy.php | 43 - .../phpFastCache/Util/OpenBaseDir.php | 33 - .../phpFastCache/phpFastCache.php | 55 -- lib/phpfastcache/src/autoload.php | 51 ++ .../{ => src}/phpFastCache/.htaccess | 0 lib/phpfastcache/src/phpFastCache/Api.php | 72 ++ .../phpFastCache/Cache/DriverBaseTrait.php | 334 +++++++ .../Cache/ExtendedCacheItemInterface.php | 170 ++++ .../Cache/ExtendedCacheItemPoolInterface.php | 357 ++++++++ .../src/phpFastCache/Cache/ItemBaseTrait.php | 447 +++++++++ .../src/phpFastCache/CacheManager.php | 270 ++++++ .../Core/ClassNamespaceResolverTrait.php} | 15 +- .../src/phpFastCache/Core/DriverAbstract.php | 67 ++ .../Core/ExtendedCacheItemPoolTrait.php | 370 ++++++++ .../MemcacheDriverCollisionDetectorTrait.php | 40 + .../src/phpFastCache/Core/PathSeekerTrait.php | 242 +++++ .../Core/StandardPsr6StructureTrait.php | 247 +++++ .../src/phpFastCache/Drivers/Apc/Driver.php | 143 +++ .../src/phpFastCache/Drivers/Apc/Item.php | 63 ++ .../src/phpFastCache/Drivers/Apcu/Driver.php | 142 +++ .../src/phpFastCache/Drivers/Apcu/Item.php | 63 ++ .../phpFastCache/Drivers/Cookie/Driver.php | 197 ++++ .../src/phpFastCache/Drivers/Cookie/Item.php | 65 ++ .../phpFastCache/Drivers/Couchbase/Driver.php | 199 ++++ .../phpFastCache/Drivers/Couchbase/Item.php | 63 ++ .../phpFastCache/Drivers/Devfalse/Driver.php | 136 +++ .../phpFastCache/Drivers/Devfalse/Item.php | 63 ++ .../phpFastCache/Drivers/Devnull/Driver.php | 138 +++ .../src/phpFastCache/Drivers/Devnull/Item.php | 63 ++ .../phpFastCache/Drivers/Devtrue/Driver.php | 138 +++ .../src/phpFastCache/Drivers/Devtrue/Item.php | 63 ++ .../src/phpFastCache/Drivers/Files/Driver.php | 239 +++++ .../src/phpFastCache/Drivers/Files/Item.php | 63 ++ .../phpFastCache/Drivers/Leveldb/Driver.php | 177 ++++ .../src/phpFastCache/Drivers/Leveldb/Item.php | 63 ++ .../phpFastCache/Drivers/Memcache/Driver.php | 176 ++++ .../phpFastCache/Drivers/Memcache/Item.php | 63 ++ .../phpFastCache/Drivers/Memcached/Driver.php | 175 ++++ .../phpFastCache/Drivers/Memcached/Item.php | 63 ++ .../phpFastCache/Drivers/Mongodb/Driver.php | 223 +++++ .../src/phpFastCache/Drivers/Mongodb/Item.php | 63 ++ .../phpFastCache/Drivers/Predis/Driver.php | 161 ++++ .../src/phpFastCache/Drivers/Predis/Item.php | 63 ++ .../src/phpFastCache/Drivers/Redis/Driver.php | 165 ++++ .../src/phpFastCache/Drivers/Redis/Item.php | 63 ++ .../phpFastCache/Drivers/Sqlite/Driver.php | 431 +++++++++ .../src/phpFastCache/Drivers/Sqlite/Item.php | 63 ++ .../src/phpFastCache/Drivers/Ssdb/Driver.php | 181 ++++ .../src/phpFastCache/Drivers/Ssdb/Item.php | 63 ++ .../phpFastCache/Drivers/Wincache/Driver.php | 138 +++ .../phpFastCache/Drivers/Wincache/Item.php | 63 ++ .../phpFastCache/Drivers/Xcache/Driver.php | 148 +++ .../src/phpFastCache/Drivers/Xcache/Item.php | 63 ++ .../phpFastCache/Drivers/Zenddisk/Driver.php | 141 +++ .../phpFastCache/Drivers/Zenddisk/Item.php | 62 ++ .../phpFastCache/Drivers/Zendshm/Driver.php | 149 +++ .../src/phpFastCache/Drivers/Zendshm/Item.php | 62 ++ .../phpFastCache/Entities/driverStatistic.php | 227 +++++ .../Exceptions/phpFastCacheCoreException.php | 0 .../phpFastCacheDriverCheckException.php} | 11 +- .../phpFastCacheDriverException.php | 0 .../Proxy/phpFastCacheAbstractProxy.php | 83 ++ .../src/phpFastCache/Util/Directory.php | 143 +++ .../{ => src}/phpFastCache/Util/Languages.php | 8 +- .../{ => src}/phpFastCache/index.html | 0 .../libraries/TeamSpeak3/Helper/String.php | 2 +- .../libraries/TeamSpeak3/Node/Channel.php | 2 - .../TeamSpeak3/Node/Channelgroup.php | 2 - .../libraries/TeamSpeak3/Node/Client.php | 2 +- .../libraries/TeamSpeak3/Node/Server.php | 6 +- .../libraries/TeamSpeak3/Node/Servergroup.php | 2 - .../TeamSpeak3/Transport/Abstract.php | 4 +- .../libraries/TeamSpeak3/Viewer/Html.php | 2 +- viewer.php | 20 +- 110 files changed, 8445 insertions(+), 4370 deletions(-) create mode 100644 cache/.gitkeep create mode 100644 cache/.htaccess create mode 100644 include/cacheutils.class.php create mode 100644 lib/phpfastcache/LICENCE create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/LICENSE.txt create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/README.md create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/composer.json create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheException.php create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheItemInterface.php create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheItemPoolInterface.php create mode 100644 lib/phpfastcache/bin/legacy/Psr/Cache/src/InvalidArgumentException.php delete mode 100644 lib/phpfastcache/phpFastCache/CacheManager.php delete mode 100644 lib/phpfastcache/phpFastCache/Core/DriverAbstract.php delete mode 100644 lib/phpfastcache/phpFastCache/Core/DriverInterface.php delete mode 100644 lib/phpfastcache/phpFastCache/Core/phpFastCache.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/apc.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/cookie.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/example.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/files.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/memcache.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/memcached.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/mongodb.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/predis.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/redis.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/sqlite.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/ssdb.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/wincache.php delete mode 100644 lib/phpfastcache/phpFastCache/Drivers/xcache.php delete mode 100644 lib/phpfastcache/phpFastCache/Plugins/CronClearFiles.php delete mode 100644 lib/phpfastcache/phpFastCache/Util/Legacy.php delete mode 100644 lib/phpfastcache/phpFastCache/Util/OpenBaseDir.php delete mode 100644 lib/phpfastcache/phpFastCache/phpFastCache.php create mode 100644 lib/phpfastcache/src/autoload.php rename lib/phpfastcache/{ => src}/phpFastCache/.htaccess (100%) create mode 100644 lib/phpfastcache/src/phpFastCache/Api.php create mode 100644 lib/phpfastcache/src/phpFastCache/Cache/DriverBaseTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemInterface.php create mode 100644 lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php create mode 100644 lib/phpfastcache/src/phpFastCache/Cache/ItemBaseTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/CacheManager.php rename lib/phpfastcache/{phpFastCache/Core/phpFastCacheExtensions.php => src/phpFastCache/Core/ClassNamespaceResolverTrait.php} (57%) create mode 100644 lib/phpfastcache/src/phpFastCache/Core/DriverAbstract.php create mode 100644 lib/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/Core/MemcacheDriverCollisionDetectorTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/Core/PathSeekerTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Apc/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Apc/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Files/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Predis/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Predis/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Redis/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Redis/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Driver.php create mode 100644 lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Item.php create mode 100644 lib/phpfastcache/src/phpFastCache/Entities/driverStatistic.php rename lib/phpfastcache/{ => src}/phpFastCache/Exceptions/phpFastCacheCoreException.php (100%) rename lib/phpfastcache/{autoload.php => src/phpFastCache/Exceptions/phpFastCacheDriverCheckException.php} (61%) rename lib/phpfastcache/{ => src}/phpFastCache/Exceptions/phpFastCacheDriverException.php (100%) create mode 100644 lib/phpfastcache/src/phpFastCache/Proxy/phpFastCacheAbstractProxy.php create mode 100644 lib/phpfastcache/src/phpFastCache/Util/Directory.php rename lib/phpfastcache/{ => src}/phpFastCache/Util/Languages.php (84%) rename lib/phpfastcache/{ => src}/phpFastCache/index.html (100%) diff --git a/.gitignore b/.gitignore index ef139ce..b4821ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ config/config.php prototypes/ admin/ +cache/localhost # PhpStorm .idea/ diff --git a/api/status.php b/api/status.php index 85e6c65..d283a84 100644 --- a/api/status.php +++ b/api/status.php @@ -4,26 +4,17 @@ header('Content-Type: application/json'); set_error_handler("exception_error_handler", E_ALL); require_once __DIR__ . "/../include/tsutils.php"; -require_once __DIR__ . "/../lib/phpfastcache/autoload.php"; +require_once __DIR__ . "/../include/cacheutils.class.php"; date_default_timezone_set($config["general"]["timezone"]); -use phpFastCache\Util; -use phpFastCache\CacheManager; +$cacheutils = new CacheUtils('serverstatus'); -Util\Languages::setEncoding("UTF-8"); -$cache = CacheManager::Files(); - -$serverstatus = $cache->get('serverstatus'); - -// $cache->clean(); - -if (is_null($serverstatus)) { - $serverstatus = getResult(); - $cache->set('serverstatus', $serverstatus, 10); +if($cacheutils->isExpired()) { + $cacheutils->setValue(getResult(), 10); } -die ($serverstatus); +die ($cacheutils->getValue()); // ********* // METHODS diff --git a/bans.php b/bans.php index f7054e0..d3fb33c 100644 --- a/bans.php +++ b/bans.php @@ -2,23 +2,15 @@ $bansPage = true; require_once __DIR__ . "/include/header.php"; require_once __DIR__ . "/include/tsutils.php"; -require_once __DIR__ . "/lib/phpfastcache/autoload.php"; +require_once __DIR__ . "/include/cacheutils.class.php"; +$cacheutils = new CacheUtils('banlist'); -use phpFastCache\Util; -use phpFastCache\CacheManager; - -Util\Languages::setEncoding("UTF-8"); -$cache = CacheManager::Files(); - -$banlist = $cache->get('banlist'); - -// $cache->clean(); - -if (is_null($banlist)) { - $banlist = array(getBanlist(), date('d-m-Y H:i:s')); - $cache->set('banlist', $banlist, 600); +if($cacheutils->isExpired()) { + $cacheutils->setValue([getBanlist(), date('d-m-Y H:i:s')], 300); } + +$banlist = $cacheutils->getValue(); ?>
diff --git a/cache/.gitkeep b/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/cache/.htaccess b/cache/.htaccess new file mode 100644 index 0000000..ec3ea62 --- /dev/null +++ b/cache/.htaccess @@ -0,0 +1,3 @@ +order deny,allow +deny from all +allow from 127.0.0.1 diff --git a/include/adminlist.php b/include/adminlist.php index dd4565a..34ea1f9 100644 --- a/include/adminlist.php +++ b/include/adminlist.php @@ -1,23 +1,14 @@ get('adminlist'); - -// $cache->clean(); - -if (is_null($adminlist)) { - $adminlist = array(getAdminList(), date('d-m-Y H:i:s')); - $cache->set('adminlist', $adminlist, 30); +if($cacheutils->isExpired()) { + $cacheutils->setValue([getAdminList(), date('d-m-Y H:i:s')], 30); } +$adminlist = $cacheutils->getValue(); // FUNCTIONS diff --git a/include/cacheutils.class.php b/include/cacheutils.class.php new file mode 100644 index 0000000..849bdb0 --- /dev/null +++ b/include/cacheutils.class.php @@ -0,0 +1,49 @@ +cacheInstance = CacheManager::getInstance('Files', ["path" => __DIR__ . '/../cache']); + Languages::setEncoding(); + $this->cacheItem = $this->cacheInstance->getItem($key); + $this->key = $key; + } + + public function getCacheInstance() { + return $this->cacheInstance; + } + + public function getCacheItem() { + return $this->cacheItem; + } + + public function getValue() { + return $this->cacheItem->get(); + } + + public function setValue($value, $expireTime) { + $this->cacheItem = $this->cacheItem->set($value)->expiresAfter($expireTime); + $this->cacheInstance->save($this->cacheItem); + } + + public function isExpired() { + return !$this->cacheItem->isHit(); + } + + public function remove() { + $this->cacheInstance->deleteItem($this->key); + } + +} diff --git a/include/footer.php b/include/footer.php index 3fd9bb0..764d194 100644 --- a/include/footer.php +++ b/include/footer.php @@ -12,7 +12,7 @@
diff --git a/lib/parsedown/parsedown.php b/lib/parsedown/parsedown.php index 70d06ff..6b55b41 100644 --- a/lib/parsedown/parsedown.php +++ b/lib/parsedown/parsedown.php @@ -515,10 +515,10 @@ class Parsedown ), ); - if($name === 'ol') + if($name === 'ol') { $listStart = stristr($matches[0], '.', true); - + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart); @@ -1208,7 +1208,7 @@ class Parsedown $remainder = $Excerpt['text']; - if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches)) + if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) { $Element['text'] = $matches[1]; @@ -1221,7 +1221,7 @@ class Parsedown return; } - if (preg_match('/^[(]((?:[^ ()]|[(][^ )]+[)])+)(?:[ ]+("[^"]*"|\'[^\']*\'))?[)]/', $remainder, $matches)) + if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) { $Element['attributes']['href'] = $matches[1]; @@ -1545,8 +1545,8 @@ class Parsedown 'q', 'rt', 'ins', 'font', 'strong', 's', 'tt', 'sub', 'mark', 'u', 'xm', 'sup', 'nobr', - 'var', 'ruby', - 'wbr', 'span', - 'time', + 'var', 'ruby', + 'wbr', 'span', + 'time', ); } diff --git a/lib/phpfastcache/LICENCE b/lib/phpfastcache/LICENCE new file mode 100644 index 0000000..59c1b7e --- /dev/null +++ b/lib/phpfastcache/LICENCE @@ -0,0 +1,20 @@ +Copyright (c) 2016 phpFastCache + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +Software), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/phpfastcache/bin/legacy/Psr/Cache/LICENSE.txt b/lib/phpfastcache/bin/legacy/Psr/Cache/LICENSE.txt new file mode 100644 index 0000000..b1c2c97 --- /dev/null +++ b/lib/phpfastcache/bin/legacy/Psr/Cache/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2015 PHP Framework Interoperability Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/lib/phpfastcache/bin/legacy/Psr/Cache/README.md b/lib/phpfastcache/bin/legacy/Psr/Cache/README.md new file mode 100644 index 0000000..c8706ce --- /dev/null +++ b/lib/phpfastcache/bin/legacy/Psr/Cache/README.md @@ -0,0 +1,9 @@ +PSR Cache +========= + +This repository holds all interfaces defined by +[PSR-6](http://www.php-fig.org/psr/psr-6/). + +Note that this is not a Cache implementation of its own. It is merely an +interface that describes a Cache implementation. See the specification for more +details. diff --git a/lib/phpfastcache/bin/legacy/Psr/Cache/composer.json b/lib/phpfastcache/bin/legacy/Psr/Cache/composer.json new file mode 100644 index 0000000..e828fec --- /dev/null +++ b/lib/phpfastcache/bin/legacy/Psr/Cache/composer.json @@ -0,0 +1,25 @@ +{ + "name": "psr/cache", + "description": "Common interface for caching libraries", + "keywords": ["psr", "psr-6", "cache"], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheException.php b/lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheException.php new file mode 100644 index 0000000..e27f22f --- /dev/null +++ b/lib/phpfastcache/bin/legacy/Psr/Cache/src/CacheException.php @@ -0,0 +1,10 @@ + http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache; - -use phpFastCache\Core\phpFastCache; -use phpFastCache\Core\DriverAbstract; - -/** - * Class CacheManager - * @package phpFastCache - * - * @method static DriverAbstract Apc() Apc($config = array()) Return a driver "apc" instance - * @method static DriverAbstract Cookie() Cookie($config = array()) Return a driver "cookie" instance - * @method static DriverAbstract Files() Files($config = array()) Return a driver "files" instance - * @method static DriverAbstract Memcache() Memcache($config = array()) Return a driver "memcache" instance - * @method static DriverAbstract Memcached() Memcached($config = array()) Return a driver "memcached" instance - * @method static DriverAbstract Predis() Predis($config = array()) Return a driver "predis" instance - * @method static DriverAbstract Redis() Redis($config = array()) Return a driver "redis" instance - * @method static DriverAbstract Sqlite() Sqlite($config = array()) Return a driver "sqlite" instance - * @method static DriverAbstract Ssdb() Ssdb($config = array()) Return a driver "ssdb" instance - * @method static DriverAbstract Wincache() Wincache($config = array()) Return a driver "wincache" instance - * @method static DriverAbstract Xcache() Xcache($config = array()) Return a driver "xcache" instance - * - */ -class CacheManager -{ - public static $instances = array(); - public static $memory = array(); - public static $hit = array(); - - /** - * @param string $storage - * @param array $config - * @return DriverAbstract - */ - public static function getInstance($storage = 'auto', $config = array()) - { - $storage = strtolower($storage); - if (empty($config)) { - $config = phpFastCache::$config; - } - if (!isset($config[ 'cache_method' ])) { - $config[ 'cache_method' ] = phpFastCache::$config[ 'cache_method' ]; - } - if (!isset($config[ 'limited_memory_each_object' ])) { - $config[ 'limited_memory_each_object' ] = phpFastCache::$config[ 'limited_memory_each_object' ]; - } - if (isset(phpFastCache::$config[ 'overwrite' ]) && !in_array(phpFastCache::$config[ 'overwrite' ], array('auto', ''), true)) { - phpFastCache::$config[ 'storage' ] = phpFastCache::$config[ 'overwrite' ]; - $storage = phpFastCache::$config[ 'overwrite' ]; - } else if (isset(phpFastCache::$config[ 'storage' ]) && !in_array(phpFastCache::$config[ 'storage' ], array('auto', ''), true)) { - $storage = phpFastCache::$config[ 'storage' ]; - } else if (in_array($storage, array('auto', ''), true)) { - $storage = phpFastCache::getAutoClass($config); - } - - // echo $storage."
"; - $instance = md5(serialize($config) . $storage); - if (!isset(self::$instances[ $instance ]) || is_null(self::$instances[ $instance ])) { - $class = '\phpFastCache\Drivers\\' . $storage; - $config[ 'storage' ] = $storage; - $config[ 'instance' ] = $instance; - $config[ 'class' ] = $class; - if (!isset(self::$memory[ $instance ])) { - self::$memory[ $instance ] = array(); - } - - if (!isset(self::$hit[ $instance ])) { - self::$hit[ $instance ] = array( - "class" => $class, - "storage" => $storage, - "data" => array(), - ); - if ($config[ 'cache_method' ] == 4) { - register_shutdown_function('phpFastCache\CacheManager::cleanCachingMethod', null); - } - } - - self::$instances[ $instance ] = new $class($config); - } - - return self::$instances[ $instance ]; - } - - /** - * Setup Method - * @param string $string | traditional(normal), memory (fast), phpfastcache (fastest) - */ - public static function CachingMethod($string = "phpFastCache") - { - $string = strtolower($string); - if (in_array($string, array("normal", "traditional"))) { - phpFastCache::$config[ 'cache_method' ] = 1; - } else if (in_array($string, array("fast", "memory"))) { - phpFastCache::$config[ 'cache_method' ] = 2; - } else if (in_array($string, array("fastest", "phpfastcache"))) { - phpFastCache::$config[ 'cache_method' ] = 3; - } else if (in_array($string, array("superfast", "phpfastcachex"))) { - phpFastCache::$config[ 'cache_method' ] = 4; - } - } - - /** - * CacheManager::Files(); - * CacheManager::Memcached(); - * CacheManager::get($keyword); - * CacheManager::set(), touch, other @method supported - */ - public static function __callStatic($name, $arguments) - { - $driver = strtolower($name); - if (!isset(self::$instances[ 'loaded' ][ $driver ]) && class_exists("\\phpFastCache\\Drivers\\{$driver}")) { - self::$instances[ 'loaded' ][ $driver ] = true; - } - if (isset(self::$instances[ 'loaded' ][ $driver ])) { - return self::getInstance($name, (isset($arguments[ 0 ]) ? $arguments[ 0 ] : array())); - } else { - return call_user_func_array(array(self::getInstance(), $name), $arguments); - } - - } - - /** - * Shortcut to phpFastCache::setup() - */ - public static function setup($name, $value = '') - { - phpFastCache::setup($name, $value); - } - - /** - * @param string $instance - */ - public static function cleanCachingMethod($instance = null) - { - if (is_null($instance)) { - foreach (self::$instances as $instance => $data) { - self::__CleanCachingMethod($instance); - unset($data); - } - } else { - self::__CleanCachingMethod($instance); - } - } - - /** - * @param string $instance - */ - protected static function __CleanCachingMethod($instance) - { - if(is_array(self::$memory[ $instance ]) && !empty(self::$memory[ $instance ])) { - $old = self::$instances[$instance]->config['cache_method']; - self::$instances[$instance]->config['cache_method'] = 1; - foreach (self::$memory[$instance] as $keyword => $object) { - self::$instances[$instance]->set($keyword, $object['value'], $object['expired_in']); - } - self::$instances[$instance]->config['cache_method'] = $old; - self::$memory[$instance] = array(); - } - } -} diff --git a/lib/phpfastcache/phpFastCache/Core/DriverAbstract.php b/lib/phpfastcache/phpFastCache/Core/DriverAbstract.php deleted file mode 100644 index b880401..0000000 --- a/lib/phpfastcache/phpFastCache/Core/DriverAbstract.php +++ /dev/null @@ -1,846 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Core; - -use phpFastCache\Exceptions\phpFastCacheDriverException; -use phpFastCache\CacheManager; - -/** - * Class DriverAbstract - * @package phpFastCache\Core - */ -abstract class DriverAbstract implements DriverInterface -{ - - /** - * @var array - */ - public $extension_dir = '_extensions'; - - /** - * @var array - */ - public $tmp = array(); - - /** - * @var array default options, this will be merge to Driver's Options - */ - public $config = array(); - - /** - * @var bool - */ - public $fallback = false; - - /** - * @var - */ - public $instant; - - - public function __destruct() - { - // clean up the memory and don't want for PHP clean for caching method "phpfastcache" - if (isset($this->config[ 'instance' ]) && (int)$this->config[ 'cache_method' ] === 3) { - CacheManager::cleanCachingMethod($this->config[ 'instance' ]); - } - } - - /** - * @param $keyword - * @return string - */ - protected function encodeFilename($keyword) - { - // return trim(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $keyword), '_')); - // return rtrim(base64_encode($keyword), '='); - return md5($keyword); - } - - /** - * 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()) - { - /** - * Infinity Time - * Khoa. B - */ - 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; - } - - /** - * Temporary disabled phpFastCache::$disabled = true - * Khoa. B - */ - if (phpFastCache::$disabled === true) { - return false; - } - $object = array( - "value" => $value, - "write_time" => time(), - "expired_in" => $time, - "expired_time" => time() + (int)$time, - "size" => (is_array($value) || is_object($value)) ? strlen(serialize($value)) : strlen((String)$value), - ); - - // handle search - if (isset($this->config[ 'allow_search' ]) && $this->config[ 'allow_search' ] == true) { - $option[ 'tags' ][] = "search"; - } - - // handle tags - if (isset($option[ 'tags' ])) { - $this->_handleTags($keyword, $time, $option[ 'tags' ]); - } - - // handle method - if ((int)$this->config[ 'cache_method' ] > 1 && isset($object[ 'size' ]) && (int)$object[ 'size' ] <= (int)$this->config[ 'limited_memory_each_object' ]) { - CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ] = $object; - if (in_array((int)$this->config[ 'cache_method' ], array(3, 4))) { - return true; - } - } - $this->_hit("set", 1); - return $this->driver_set($keyword, $object, $time, $option); - - } - - /** - * @param $keyword - * @param array $option - * @return mixed - */ - public function get($keyword, $option = array()) - { - /** - * Temporary disabled phpFastCache::$disabled = true - * Khoa. B - */ - - if (phpFastCache::$disabled === true) { - return null; - } - - // handle method - if ((int)$this->config[ 'cache_method' ] > 1) { - if (isset(CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ])) { - $object = CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ]; - } - } - - if (!isset($object)) { - $this->_hit("get", 1); - $object = $this->driver_get($keyword, $option); - - // handle method - if ((int)$this->config[ 'cache_method' ] > 1 && isset($object[ 'size' ]) && (int)$object[ 'size' ] <= (int)$this->config[ 'limited_memory_each_object' ]) { - CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ] = $object; - } - // end handle method - } - - if ($object == null) { - return null; - } - - $value = isset($object[ 'value' ]) ? $object[ 'value' ] : null; - return isset($option[ 'all_keys' ]) && $option[ 'all_keys' ] ? $object : $value; - } - - /** - * @param $keyword - * @param array $option - * @return null|object - */ - public function getInfo($keyword, $option = array()) - { - if ((int)$this->config[ 'cache_method' ] > 1) { - if (isset(CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ])) { - $object = CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ]; - } - } - if (!isset($object)) { - $object = $this->driver_get($keyword, $option); - } - if ($object == null) { - return null; - } - return $object; - } - - /** - * @param $keyword - * @param array $option - * @return mixed - */ - public function delete($keyword, array $option = array()) - { - // handle method - if ((int)$this->config[ 'cache_method' ] > 1) { - // use memory - unset(CacheManager::$memory[ $this->config[ 'instance' ] ][ $keyword ]); - } - // end handle method - return $this->driver_delete($keyword, $option); - } - - /** - * @param array $option - * @return mixed - */ - public function stats(array $option = array()) - { - return $this->driver_stats($option); - } - - /** - * @param array $option - * @return mixed - */ - public function clean(array $option = array()) - { - // handle method - if ((int)$this->config[ 'cache_method' ] > 1) { - // use memory - CacheManager::$memory[ $this->config[ 'instance' ] ] = array(); - } - // end handle method - return $this->driver_clean($option); - } - - /** - * @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) { - return false; - } else { - return true; - } - - } - - /** - * Searches though the cache for keys that match the given query. - * @param $query_as_regex_or_string - * @param bool $search_in_value - * @return mixed - * @throws phpFastCacheDriverException - */ - public function search($query_as_regex_or_string, $search_in_value = false) - { - if ($this->config[ 'allow_search' ] != true) { - throw new phpFastCacheDriverException('Please setup allow_search = true'); - } else { - $list = $this->getTags("search", $search_in_value); - $tmp = explode("/", $query_as_regex_or_string, 2); - $regex = isset($tmp[ 1 ]) ? true : false; - $return_list = array(); - foreach ($list as $tag) { - foreach ($tag as $keyword => $value) { - $gotcha = false; - if ($search_in_value == true) { - $value = $this->get($keyword); - } - - if ($regex == true && $gotcha == false) { // look in keyword - if (preg_match($query_as_regex_or_string, $keyword)) { - $return_list[ $keyword ] = $value; - $gotcha = true; - } - } - if ($gotcha == false) { - if (strpos($keyword, $query_as_regex_or_string) !== false) { - $return_list[ $keyword ] = $value; - $gotcha = true; - } - } - - if ($search_in_value == true && $gotcha == false) { // value search - if ($regex == true && $gotcha == false) { - if (preg_match($query_as_regex_or_string, $value)) { - $return_list[ $keyword ] = $value; - $gotcha = true; - } - } - if ($gotcha == false) { - if (strpos($value, $query_as_regex_or_string) !== false) { - $return_list[ $keyword ] = $value; - $gotcha = true; - } - } - } - } // each tags loop - } // end foreach - return $return_list; - } - } - - /** - * @param $keyword - * @param int $step - * @param array $option - * @return bool - */ - public function increment($keyword, $step = 1, array $option = array()) - { - $object = $this->get($keyword, array('all_keys' => true)); - if ($object == null) { - return false; - } else { - $value = (int)$object[ 'value' ] + (int)$step; - $time = $object[ 'expired_time' ] - time(); - $this->set($keyword, $value, $time, $option); - return true; - } - } - - /** - * @param $keyword - * @param int $step - * @param array $option - * @return bool - */ - public function decrement($keyword, $step = 1, array $option = array()) - { - $object = $this->get($keyword, array('all_keys' => true)); - if ($object == null) { - return false; - } else { - $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 - */ - public function touch($keyword, $time = 300, array $option = array()) - { - $object = $this->get($keyword, array('all_keys' => true)); - if ($object == null) { - return false; - } else { - $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 - */ - - /** - * @param array $list - */ - public function setMulti(array $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 - * @return array - */ - public function getMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->get($name, - isset($array[ 1 ]) ? $array[ 1 ] : array()); - } - return $res; - } - - /** - * @param array $list - * @return array - */ - public function getInfoMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->getInfo($name, - isset($array[ 1 ]) ? $array[ 1 ] : array()); - } - return $res; - } - - /** - * @param array $list - * @param array $option - */ - public function deleteMulti(array $list = array(), array $option = array()) - { - foreach ($list as $item) { - if (is_array($item) && count($item) === 2) { - $this->delete($item[ 0 ], $item[ 1 ]); - } - } - } - - /** - * @param array $list - * @return array - */ - public function isExistingMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->isExisting($name); - } - return $res; - } - - /** - * @param array $list - * @return array - */ - public function incrementMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->increment($name, $array[ 1 ], - isset($array[ 2 ]) ? $array[ 2 ] : array()); - } - return $res; - } - - /** - * @param array $list - * @return array - */ - public function decrementMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->decrement($name, $array[ 1 ], - isset($array[ 2 ]) ? $array[ 2 ] : array()); - } - return $res; - } - - /** - * @param array $list - * @return array - */ - public function touchMulti(array $list = array()) - { - $res = array(); - foreach ($list as $array) { - $name = $array[ 0 ]; - $res[ $name ] = $this->touch($name, $array[ 1 ], - isset($array[ 2 ]) ? $array[ 2 ] : array()); - } - return $res; - } - - /** - * @param $config_name - * @param string $value - */ - public function setup($config_name, $value = '') - { - /* - * Config for class - */ - if (is_array($config_name)) { - $this->config = array_merge($this->config, $config_name); - } else { - $this->config[ $config_name ] = $value; - } - } - - /** - * @param int $time - */ - public function autoCleanExpired($time = 3600) - { - } - - /** - * Magic methods - */ - - /** - * @param $name - * @return mixed - */ - public function __get($name) - { - return $this->get($name); - } - - /** - * @param $name - * @param $v - * @return bool|null - * @throws \Exception - */ - public function __set($name, $v) - { - if (isset($v[ 1 ]) && is_scalar($v[ 1 ])) { - return $this->set($name, $v[ 0 ], $v[ 1 ], - isset($v[ 2 ]) ? $v[ 2 ] : array()); - } else { - throw new phpFastCacheDriverException("Example ->$name = array('VALUE', 300);", 98); - } - } - - - /** - * Base Methods - */ - - - /** - * @return mixed - */ - protected function backup() - { - return phpFastCache(phpFastCache::$config[ 'fallback' ]); - } - - /** - * @param $name - * @return void - */ - protected function required_extension($name) - { - require_once(__DIR__ . '/../' . $this->extension_dir . '/' . $name . '.' . PHP_EXT); - } - - - /** - * @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 phpFastCacheDriverException("Can't Read File", 96); - - } - while (!feof($file_handle)) { - $line = fgets($file_handle); - $string .= $line; - } - fclose($file_handle); - - return $string; - } - } - - /** - * 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); - } - - - /** - * Object for Files & SQLite - * @param $data - * @return string - */ - protected function encode($data) - { - return serialize($data); - } - - /** - * @param $value - * @return mixed - */ - protected function decode($value) - { - $x = @unserialize($value); - if ($x == false) { - return $value; - } else { - return $x; - } - } - - /** - * Check phpModules or CGI - * @return bool - */ - protected function isPHPModule() - { - return phpFastCache::isPHPModule(); - } - - - /** - * @param $class - * @return bool - */ - protected function isExistingDriver($class) - { - return class_exists("\\phpFastCache\\Drivers\\{$class}"); - } - - - /** - * @return int - */ - protected function __setChmodAuto() - { - return phpFastCache::__setChmodAuto($this->config); - } - - - /** - * @param $tag - * @return string - */ - protected function _getTagName($tag) - { - return "__tag__" . $tag; - } - - /** - * @return \phpFastCache\Core\DriverAbstract - */ - protected function _tagCaching() - { - return CacheManager::Sqlite( - array( - "path" => $this->config[ 'path' ], - "cache_method" => 3, - ) - ); - } - - /** - * @param string $keyword - * @param mixed $value - * @param integer $time - * @param array $tags - * @param array $option | $option = array("tags" => array("a","b","c") - * @return mixed - */ - public function setTags($keyword, $value = '', $time = 0, $tags = array(), $option = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $option[ 'tags' ] = $tags; - return $this->set($keyword, $value, $time, $option); - } - - protected function _handleTags($keyword, $time, $tags) - { - foreach ($tags as $tag) { - $list = $this->_tagCaching()->get($this->_getTagName($tag)); - if (is_null($list)) { - $list = array(); - } - $list[ $keyword ] = time() + $time; - $this->_tagCaching()->set($this->_getTagName($tag), $list, 3600 * 24 * 30); - } - } - - - /** - * @param array $tags - * @param bool $return_content - * @param array $option | $option = array("tags" => array("a","b","c") - * @return array - */ - public function getTags($tags = array(), $return_content = true, $option = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $keywords = array(); - $tmp = 0; - - foreach ($tags as $tag) { - $list = $this->_tagCaching()->get($this->_getTagName($tag)); - $list_return = array(); - if (is_null($list)) { - $list = array(); - } - foreach ($list as $keyword => $time) { - if ($time <= time()) { - unset($list[ $keyword ]); - } else { - if ($tmp < $time) { - $tmp = $time; - } - if ($return_content == true) { - $list_return[ $keyword ] = $this->get($keyword); - } else { - $list_return[ $keyword ] = $time; - } - } - } - - $this->_tagCaching()->set($this->_getTagName($tag), $list, $tmp); - $keywords[ $tag ] = $list_return; - } - return $keywords; - } - - /** - * @param array $tags | array("a","b","c") - * @param int $time - * @param array $options - * @return mixed - * @internal param array $option | $option = array("tags" => array("a","b","c") - */ - public function touchTags($tags = array(), $time = 300, $options = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $lists = $this->getTags($tags); - foreach ($lists as $tag => $keywords) { - foreach ($keywords as $keyword => $time) { - $this->touch($keyword, $time, $options); - } - } - return true; - } - - /** - * @param array $tags | array("a","b","c") - * @param array $option | $option = array("tags" => array("a","b","c") - * @return mixed - */ - public function deleteTags($tags = array(), $option = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $lists = $this->getTags($tags); - foreach ($lists as $tag => $keywords) { - foreach ($keywords as $keyword => $time) { - $this->delete($keyword, $option); - } - } - return true; - } - - - /** - * @param array $tags | array("a","b","c") - * @param integer - * @param array $option | $option = array("tags" => array("a","b","c") - * @return mixed - */ - public function incrementTags($tags = array(), $step = 1, $option = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $lists = $this->getTags($tags); - foreach ($lists as $tag => $keywords) { - foreach ($keywords as $keyword => $time) { - $this->increment($keyword, $step, $option); - } - } - return true; - } - - /** - * @param array $tags | array("a","b","c") - * @param integer - * @param array $option | $option = array("tags" => array("a","b","c") - * @return mixed - */ - public function decrementTags($tags = array(), $step = 1, $option = array()) - { - if (!is_array($tags)) { - $tags = array($tags); - } - $lists = $this->getTags($tags); - foreach ($lists as $tag => $keywords) { - foreach ($keywords as $keyword => $time) { - $this->decrement($keyword, $step, $option); - } - } - return true; - } - - /** - * @param $value - */ - protected function _kbdebug($value) - { - /* - echo "
";
-        print_r($value);
-        echo "
"; - */ - } - - public function _hit($index, $step = 1) - { - $instance = $this->config[ 'instance' ]; - $current = isset(CacheManager::$hit[ $instance ][ 'data' ][ $index ]) ? CacheManager::$hit[ $instance ][ 'data' ][ $index ] : 0; - CacheManager::$hit[ $instance ][ 'data' ][ $index ] = $current + ($step); - } - -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Core/DriverInterface.php b/lib/phpfastcache/phpFastCache/Core/DriverInterface.php deleted file mode 100644 index 1724374..0000000 --- a/lib/phpfastcache/phpFastCache/Core/DriverInterface.php +++ /dev/null @@ -1,86 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Core; - -/** - * Interface DriverInterface - * @package phpFastCache\Core - */ -interface DriverInterface -{ - /** - * Check if this Cache driver is available for server or not - * phpFastCache_driver constructor. - * @param array $config - */ - public function __construct($config = array()); - - /** - * @return mixed - */ - public function checkdriver(); - - /** - * Set a obj to cache - * @param $keyword - * @param string $value - * @param int $time - * @param array $option - * @return mixed - */ - public function driver_set( - $keyword, - $value = '', - $time = 300, - $option = array() - ); - - /** - * Return null or value of cache - * @param $keyword - * @param array $option - * @return mixed - */ - public function driver_get($keyword, $option = array()); - - /** - * Show stats of caching - * Return array("info","size","data") - * @param array $option - * @return mixed - */ - public function driver_stats($option = array()); - - /** - * Delete a cache - * @param $keyword - * @param array $option - * @return mixed - */ - public function driver_delete($keyword, $option = array()); - - /** - * Clean up whole cache - * @param array $option - * @return mixed - */ - public function driver_clean($option = array()); - - /** - * @param $config_name - * @param string $value - */ - public function setup($config_name, $value = ''); -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Core/phpFastCache.php b/lib/phpfastcache/phpFastCache/Core/phpFastCache.php deleted file mode 100644 index e584e85..0000000 --- a/lib/phpfastcache/phpFastCache/Core/phpFastCache.php +++ /dev/null @@ -1,354 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Core; - -use phpFastCache\CacheManager; -use phpFastCache\Exceptions\phpFastCacheCoreException; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class phpFastCache - * @package phpFastCache\Core - * - * Handle methods using annotations for IDE - * because they're handled by __call() - * Check out DriverInterface to see all - * the drivers methods magically implemented - * - * @method get() driver_get($keyword, $option = array()) Return null or value of cache - * @method set() driver_set($keyword, $value = '', $time = 300, $option = array()) Set a obj to cache - * @method delete() delete(string $keyword) Delete key from cache - * @method clean() clean($option = array()) Clean up whole cache - * @method checkdriver() checkdriver() Delete key from cache - * @method stats() stats($option = array()) Show stats of caching - * @method systemInfo() systemInfo() Return System Information - * - */ -class phpFastCache -{ - /** - * @var bool - */ - public static $disabled = false; - - /** - * @var array - */ - public static $config = array( - 'storage' => '', // blank for auto - 'default_chmod' => 0777, // 0777 , 0666, 0644 - - 'overwrite' => "", // files, sqlite, etc it will overwrite ur storage and all other caching for waiting u fix ur server - 'allow_search' => false, // turn to true will allow $method search("/regex/") - - '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(), - "cache_method" => 1, // 1 = normal, 2 = phpfastcache, 3 = memory - "limited_memory_each_object" => 4000, // maximum size (bytes) of object store in memory - "compress_data" => false // compress stored data, if the backend supports it - ); - - /** - * @var array - */ - protected static $tmp = array(); - - /** - * @var DriverAbstract $instance - */ - public $instance; - - /** - * phpFastCache constructor. - * @param string $storage - * @param array $config - */ - public function __construct($storage = '', $config = array()) - { - if (empty($config)) { - $config = phpFastCache::$config; - } - $config[ 'storage' ] = $storage; - - $storage = strtolower($storage); - if ($storage == '' || $storage == 'auto') { - $storage = self::getAutoClass($config); - } - - $this->instance = CacheManager::getInstance($storage, $config); - } - - /** - * Cores - */ - - /** - * @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) { - $driver = 'apc'; - } else if (class_exists('memcached')) { - $driver = 'memcached'; - } elseif (extension_loaded('wincache') && function_exists('wincache_ucache_set')) { - $driver = 'wincache'; - } elseif (extension_loaded('xcache') && function_exists('xcache_get')) { - $driver = 'xcache'; - } else if (function_exists('memcache_connect')) { - $driver = 'memcache'; - } else if (class_exists('Redis')) { - $driver = 'redis'; - } else { - $driver = 'files'; - } - - return $driver; - } - - /** - * @param bool $skip_create_path - * @param $config - * @return string - * @throws \Exception - */ - public static function getPath($skip_create_path = false, $config) - { - $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); - - if (!isset($config[ 'path' ]) || $config[ 'path' ] == '') { - if (self::isPHPModule()) { - $path = $tmp_dir; - } else { - $document_root_path = rtrim($_SERVER[ 'DOCUMENT_ROOT' ], '/') . '/../'; - $path = isset($_SERVER[ 'DOCUMENT_ROOT' ]) && is_writable($document_root_path) - ? $document_root_path - : rtrim(__DIR__, '/') . '/'; - } - - if (self::$config[ 'path' ] != '') { - $path = $config[ 'path' ]; - } - - } else { - $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(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ]))) : "default"; - } - } - if ($securityKey != '') { - $securityKey .= '/'; - } - - $securityKey = self::cleanFileName($securityKey); - - $full_path = rtrim($path,'/') . '/' . $securityKey; - $full_pathx = md5($full_path); - - - 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), true); - } - if (!@is_writable($full_path)) { - @chmod($full_path, self::__setChmodAuto($config)); - } - if(!@is_writable($full_path)) { - // switch back to tmp dir again if the path is not writeable - $full_path = rtrim($tmp_dir,'/') . '/' . $securityKey; - if (!@file_exists($full_path)) { - @mkdir($full_path, self::__setChmodAuto($config), true); - } - if (!@is_writable($full_path)) { - @chmod($full_path, self::__setChmodAuto($config)); - } - } - if (!@file_exists($full_path) || !@is_writable($full_path)) { - throw new phpFastCacheCoreException('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); - } - - return realpath($full_path); - - } - - /** - * @param $filename - * @return mixed - */ - public static function cleanFileName($filename) - { - $regex = array( - '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', - '/\.$/', - '/^\./', - ); - $replace = array('-', '', ''); - return trim(preg_replace($regex, $replace, trim($filename)),'-'); - } - - /** - * @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 array - */ - protected static function getOS() - { - $os = array( - 'os' => PHP_OS, - 'php' => PHP_SAPI, - 'system' => php_uname(), - 'unique' => md5(php_uname() . PHP_OS . PHP_SAPI), - ); - return $os; - } - - /** - * @return bool - */ - public static function isPHPModule() - { - if (PHP_SAPI === 'apache2handler') { - return true; - } else { - if (strpos(PHP_SAPI, 'handler') !== false) { - return true; - } - } - return false; - } - - /** - * @param $path - * @param bool $create - * @throws \Exception - */ - protected static function htaccessGen($path, $create = true) - { - - if ($create == true) { - if (!is_writable($path)) { - try { - chmod($path, 0777); - } catch (phpFastCacheDriverException $e) { - throw new phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', - 92); - } - } - - 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 phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 92); - } - fwrite($f, $html); - fclose($f); - - - } - } - - } - - /** - * @param $name - * @param string $value - */ - public static function setup($name, $value = '') - { - if (is_array($name)) { - self::$config = array_merge(self::$config,$name); - } else { - self::$config[ $name ] = $value; - } - } - - /** - * @param $something - */ - public static function debug($something) - { - echo "Starting Debugging ...
\r\n "; - if (is_array($something)) { - echo '
';
-            print_r($something);
-            echo '
'; - var_dump($something); - } else { - echo $something; - } - echo "\r\n
Ended"; - exit; - } -} diff --git a/lib/phpfastcache/phpFastCache/Drivers/apc.php b/lib/phpfastcache/phpFastCache/Drivers/apc.php deleted file mode 100644 index 36618fe..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/apc.php +++ /dev/null @@ -1,137 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class apc - * @package phpFastCache\Drivers - */ -class apc extends DriverAbstract -{ - /** - * phpFastCache_apc constructor. - * @param array $config - * @throws phpFastCacheDriverException - */ - public function __construct($config = array()) - { - $this->setup($config); - - if (!$this->checkdriver()) { - throw new phpFastCacheDriverException('APC is not installed, cannot continue.'); - } - } - - /** - * @return bool - */ - public function checkdriver() - { - if (extension_loaded('apc') && ini_get('apc.enabled')) { - return true; - } else { - $this->fallback = true; - return false; - } - } - - /** - * @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); - } - } - - /** - * @param $keyword - * @param array $option - * @return mixed|null - */ - public function driver_get($keyword, $option = array()) - { - $data = apc_fetch($keyword, $bo); - if ($bo === false) { - return null; - } - return $data; - - } - - /** - * @param $keyword - * @param array $option - * @return bool|\string[] - */ - public function driver_delete($keyword, $option = array()) - { - return apc_delete($keyword); - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - - try { - $res[ 'data' ] = apc_cache_info('user'); - } catch (\Exception $e) { - $res[ 'data' ] = array(); - } - - return $res; - } - - /** - * @param array $option - * @return void - */ - public function driver_clean($option = array()) - { - @apc_clear_cache(); - @apc_clear_cache('user'); - } - - /** - * @param $keyword - * @return bool - */ - public function driver_isExisting($keyword) - { - return (bool) apc_exists($keyword); - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Drivers/cookie.php b/lib/phpfastcache/phpFastCache/Drivers/cookie.php deleted file mode 100644 index 1326241..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/cookie.php +++ /dev/null @@ -1,156 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; - -/** - * Class cookie - * @package phpFastCache\Drivers - */ -class cookie extends DriverAbstract -{ - /** - * phpFastCache_cookie 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 - 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; - $v = $this->encode($value); - if(isset($this->config['limited_memory_each_object']) - && strlen($v) > $this->config['limited_memory_each_object']) { - return false; - } - return setcookie($keyword, $v, time() + ($time ? (int)$time : 300), '/'); - - } - - /** - * @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/lib/phpfastcache/phpFastCache/Drivers/example.php b/lib/phpfastcache/phpFastCache/Drivers/example.php deleted file mode 100644 index 7d34b57..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/example.php +++ /dev/null @@ -1,128 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use phpFastCache\Core\DriverInterface; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class example - * @package phpFastCache\Drivers - */ -class example extends DriverAbstract -{ - /** - * phpFastCache_example constructor. - * @param array $config - * @throws phpFastCacheDriverException - */ - public function __construct($config = array()) - { - $this->setup($config); - if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { - throw new phpFastCacheDriverException("Can't use this driver for your website!"); - } - - } - - /** - * @return bool - */ - public function checkdriver() - { - return false; - } - - /** - * - */ - public function connectServer() - { - - } - - /** - * @param $keyword - * @param string $value - * @param int $time - * @param array $option - * @return void - */ - public function driver_set($keyword, $value = '', $time = 300, $option = array()) - { - if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { - // skip driver - } else { - // add driver - } - - } - - /** - * @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; - } - - /** - * @param $keyword - * @param array $option - * @return void - */ - public function driver_delete($keyword, $option = array()) - { - - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - - return $res; - } - - /** - * @param array $option - * @return void - */ - public function driver_clean($option = array()) - { - - } - - /** - * @param $keyword - */ - public function driver_isExisting($keyword) - { - - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Drivers/files.php b/lib/phpfastcache/phpFastCache/Drivers/files.php deleted file mode 100644 index c8a46c1..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/files.php +++ /dev/null @@ -1,306 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class files - * @package phpFastCache\Drivers - */ -class files extends DriverAbstract -{ - /** - * Init Cache Path - * phpFastCache_files constructor. - * @param array $config - * @throws phpFastCacheDriverException - */ - public function __construct($config = array()) - { - $this->setup($config); - $this->getPath(); // force create path - - if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { - throw new phpFastCacheDriverException("Can't use this driver for your website!"); - } - } - - /** - * @return bool - */ - public function checkdriver() - { - if (is_writable($this->getPath())) { - return true; - }/* else { - - }*/ - return false; - } - - /** - * @param $keyword - * @param bool $skip - * @return string - * @throws phpFastCacheDriverException - */ - private function getFilePath($keyword, $skip = false) - { - $path = $this->getPath(); - - $filename = $this->encodeFilename($keyword); - $folder = substr($filename, 0, 2); - $path = rtrim($path, '/') . '/' . $folder; - /** - * Skip Create Sub Folders; - */ - if ($skip == false) { - if (!file_exists($path)) { - if (!mkdir($path, $this->__setChmodAuto(), true)) { - throw new phpFastCacheDriverException('PLEASE CHMOD ' . $this->getPath() . ' - 0777 OR ANY WRITABLE PERMISSION!', 92); - } - } - } - - return $path . '/' . $filename . '.txt'; - } - - /** - * @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); - $data = $this->encode($value); - - $toWrite = true; - /* - * Skip if Existing Caching in Options - */ - 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)) { - $toWrite = true; - } - } - - // Force write - try { - if ($toWrite == true) { - $f = fopen($file_path, 'w+'); - fwrite($f, $data); - fclose($f); - return true; - } - } catch (\Exception $e) { - return false; - } - - return false; - } - - /** - * @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)) { - return null; - } - - $content = $this->readfile($file_path); - $object = $this->decode($content); - if ($this->isExpired($object)) { - @unlink($file_path); - $this->autoCleanExpired(); - return null; - } - - return $object; - } - - /** - * @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; - } - } - - /** - * Return total cache size + auto removed expired files - * @param array $option - * @return array - * @throws \Exception - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - - $path = $this->getPath(); - $dir = @opendir($path); - if (!$dir) { - throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94); - } - - $total = 0; - $removed = 0; - while ($file = readdir($dir)) { - if ($file != '.' && $file != '..' && is_dir($path . '/' . $file)) { - // read sub dir - $subdir = opendir($path . "/" . $file); - if (!$subdir) { - throw new phpFastCacheDriverException("Can't read path:" . $path . '/' . $file, 93); - } - - 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) { - $key = $f; - } else { - //Because PHP 5.3, this cannot be written in single line - $key = explode('.', $f); - $key = $key[ 0 ]; - } - $content[ $key ] = array( - 'size' => $size, - 'write_time' => (isset($object[ 'write_time' ]) ? $object[ 'write_time' ] : null), - ); - if ($this->isExpired($object)) { - @unlink($file_path); - $removed += $size; - } - $total += $size; - } - } - } - } - - $res[ 'size' ] = $total - $removed; - $res[ 'info' ] = array( - 'Total [bytes]' => $total, - 'Expired and removed [bytes]' => $removed, - 'Current [bytes]' => $res[ 'size' ], - ); - $res[ "data" ] = $content; - return $res; - } - - - /** - * @param int $time - */ - public function autoCleanExpired($time = 3600) - { - $autoclean = $this->get('keyword_clean_up_driver_files'); - if ($autoclean == null) { - $this->set('keyword_clean_up_driver_files', $time); - $res = $this->stats(); - } - } - - /** - * @param array $option - * @throws \Exception - * @return void - */ - public function driver_clean($option = array()) - { - - $path = $this->getPath(); - $dir = @opendir($path); - if (!$dir) { - throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94); - } - - while ($file = readdir($dir)) { - if ($file != '.' && $file != '..' && is_dir($path . '/' . $file)) { - // read sub dir - $subdir = @opendir($path . '/' . $file); - if (!$subdir) { - throw new phpFastCacheDriverException("Can't read path:" . $path . '/' . $file, 93); - } - - while ($f = readdir($subdir)) { - if ($f != '.' && $f != '..') { - $file_path = $path . '/' . $file . '/' . $f; - @unlink($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); - - return !($value == null); - } - } - - /** - * @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/lib/phpfastcache/phpFastCache/Drivers/memcache.php b/lib/phpfastcache/phpFastCache/Drivers/memcache.php deleted file mode 100644 index 9ba830c..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/memcache.php +++ /dev/null @@ -1,200 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use Memcache as MemcacheSoftware; - -/** - * Class memcache - * @package phpFastCache\Drivers - */ -class memcache extends DriverAbstract -{ - - /** - * @var \Memcache - */ - public $instant; - - /** - * @var int - */ - protected $memcacheFlags = 0; - - /** - * 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 MemcacheSoftware(); - - if (array_key_exists('compress_data', $config) && $config[ 'compress_data' ] === true) { - $this->memcacheFlags = MEMCACHE_COMPRESSED; - } - } else { - $this->fallback = true; - } - } - - /** - * @return bool - */ - public function checkdriver() - { - // Check memcache - if (function_exists('memcache_connect')) { - return true; - } - $this->fallback = true; - return false; - } - - /** - * - */ - public function connectServer() - { - $server = $this->config[ 'memcache' ]; - if (count($server) < 1) { - $server = array( - 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; - } - - $this->checked[ $name ] = 1; - } catch (\Exception $e) { - $this->fallback = true; - } - - - } - - } - } - - /** - * @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, $this->memcacheFlags, $time); - - } else { - return $this->instant->set($keyword, $value, $this->memcacheFlags, $time); - } - } - - /** - * @param $keyword - * @param array $option - * @return array|null|string - */ - public function driver_get($keyword, $option = array()) - { - $this->connectServer(); - - // return null if no caching - // return value if in caching - - $x = $this->instant->get($keyword); - - if ($x == false) { - return null; - } else { - return $x; - } - - } - - /** - * @param $keyword - * @param array $option - */ - public function driver_delete($keyword, $option = array()) - { - $this->connectServer(); - $this->instant->delete($keyword); - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $this->connectServer(); - $res = array( - 'info' => '', - 'size' => '', - 'data' => $this->instant->getStats(), - ); - - return $res; - - } - - /** - * @param array $option - */ - public function driver_clean($option = array()) - { - $this->connectServer(); - $this->instant->flush(); - } - - /** - * @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/lib/phpfastcache/phpFastCache/Drivers/memcached.php b/lib/phpfastcache/phpFastCache/Drivers/memcached.php deleted file mode 100644 index a93735f..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/memcached.php +++ /dev/null @@ -1,200 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use Memcached as MemcachedSoftware; - -/** - * Class memcached - * @package phpFastCache\Drivers - */ -class memcached extends DriverAbstract -{ - - /** - * @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 MemcachedSoftware(); - } else { - $this->fallback = true; - } - - } - - /** - * @return bool - */ - public function checkdriver() - { - if (class_exists('Memcached')) { - return true; - } - $this->fallback = true; - return false; - } - - - /** - * @return bool - */ - public function connectServer() - { - if ($this->checkdriver() == false) { - return false; - } - - $s = $this->config[ 'memcache' ]; - if (count($s) < 1) { - $s = array( - 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; - } - - } - } - } - - /** - * @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 (isset($option[ 'isExisting' ]) && $option[ 'isExisting' ] == true) { - return $this->instant->add($keyword, $value, $time); - } else { - return $this->instant->set($keyword, $value, $time); - - } - } - - /** - * @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);// Prevent memcached to return a warning for long keywords - if ($x == false) { - return null; - } else { - return $x; - } - } - - /** - * @param $keyword - * @param array $option - * @return void - */ - public function driver_delete($keyword, $option = array()) - { - $this->connectServer(); - $this->instant->delete($keyword); - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $this->connectServer(); - $res = array( - 'info' => '', - 'size' => '', - 'data' => $this->instant->getStats(), - ); - - return $res; - } - - /** - * @param array $option - * @return void - */ - public function driver_clean($option = array()) - { - $this->connectServer(); - $this->instant->flush(); - } - - /** - * @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/lib/phpfastcache/phpFastCache/Drivers/mongodb.php b/lib/phpfastcache/phpFastCache/Drivers/mongodb.php deleted file mode 100644 index 2b8d230..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/mongodb.php +++ /dev/null @@ -1,125 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class mongodb - * @package phpFastCache\Drivers - */ -class mongodb extends DriverAbstract -{ - /** - * phpFastCache constructor. - * @param array $config - * @throws phpFastCacheDriverException - */ - public function __construct($config = array()) - { - $this->setup($config); - if (!$this->checkdriver() && !isset($config[ 'skipError' ])) { - throw new phpFastCacheDriverException("Can't use this driver for your website!"); - } - - } - - /** - * @return bool - */ - public function checkdriver() - { - // return true; - return false; - } - - /** - * - */ - public function connectServer() - { - - } - - /** - * @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 - } - - } - - /** - * @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; - } - - /** - * @param $keyword - * @param array $option - */ - public function driver_delete($keyword, $option = array()) - { - - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - - return $res; - } - - /** - * @param array $option - */ - public function driver_clean($option = array()) - { - - } - - /** - * @param $keyword - */ - public function driver_isExisting($keyword) - { - - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Drivers/predis.php b/lib/phpfastcache/phpFastCache/Drivers/predis.php deleted file mode 100644 index c0654e8..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/predis.php +++ /dev/null @@ -1,222 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use Predis\Client as PredisSoftware; - -/** - * Class predis - * @package phpFastCache\Drivers - */ -class predis extends DriverAbstract -{ - - /** - * @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"); - } - } - - /** - * @return bool - */ - public function checkdriver() - { - // Check memcache - if (!class_exists("\\Predis\\Client")) { - $this->required_extension("predis-1.0/autoload"); - try { - \Predis\Autoloader::register(); - } catch (\Exception $e) { - - } - } - 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 PredisSoftware($c); - - $this->checked_redis = true; - - if (!$this->instant) { - $this->fallback = true; - return false; - } else { - return true; - } - } - - return true; - } - - /** - * @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); - } - } - - /** - * @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); - } - } - - /** - * @param $keyword - * @param array $option - */ - public function driver_delete($keyword, $option = array()) - { - - if ($this->connectServer()) { - $this->instant->del($keyword); - } - - } - - /** - * @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(); - - } - - /** - * @param array $option - * @return void - */ - public function driver_clean($option = array()) - { - if ($this->connectServer()) { - $this->instant->flushDB(); - } - - } - - /** - * @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); - } - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Drivers/redis.php b/lib/phpfastcache/phpFastCache/Drivers/redis.php deleted file mode 100644 index 8ca4195..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/redis.php +++ /dev/null @@ -1,225 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use Redis as RedisSoftware; - -/** - * Class redis - * @package phpFastCache\Drivers - */ -class redis extends DriverAbstract -{ - - /** - * @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 RedisSoftware(); - } - - } - - /** - * @return bool - */ - public function checkdriver() - { - // Check memcache - if (class_exists('Redis')) { - return true; - } - $this->fallback = true; - return false; - } - - - /** - * @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; - } - } - - return 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 ($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); - } - } - - /** - * @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); - } - - } - - /** - * @param $keyword - * @param array $option - * @return void - */ - public function driver_delete($keyword, $option = array()) - { - if ($this->connectServer()) { - $this->instant->delete($keyword); - } - } - - /** - * @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(); - } - - /** - * @param array $option - */ - public function driver_clean($option = array()) - { - if ($this->connectServer()) { - $this->instant->flushDB(); - } - - } - - /** - * @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); - } - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Drivers/sqlite.php b/lib/phpfastcache/phpFastCache/Drivers/sqlite.php deleted file mode 100644 index 8d45201..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/sqlite.php +++ /dev/null @@ -1,482 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use PDO; -use PDOException; -use phpFastCache\Exceptions\phpFastCacheDriverException; - -/** - * Class sqlite - * @package phpFastCache\Drivers - */ -class sqlite extends DriverAbstract -{ - /** - * - */ - const SQLITE_DIR = 'sqlite'; - /** - * - */ - const INDEXING_FILE = 'indexing'; - - /** - * @var int - */ - public $max_size = 10; // 10 mb - - /** - * @var array - */ - public $instant = array(); - /** - * @var null - */ - public $indexing = null; - /** - * @var string - */ - public $path = ''; - - /** - * @var int - */ - public $currentDB = 1; - - /** - * Init Main Database & Sub Database - * phpFastCache_sqlite constructor. - * @param array $config - * @throws phpFastCacheDriverException - */ - public function __construct($config = array()) - { - /** - * init the path - */ - $this->setup($config); - if (!$this->checkdriver()) { - throw new phpFastCacheDriverException('SQLITE is not installed, cannot continue.'); - } - - if (!file_exists($this->getPath() . '/' . self::SQLITE_DIR)) { - if (!mkdir($this->getPath() . '/' . self::SQLITE_DIR, $this->__setChmodAuto(), true)) { - $this->fallback = true; - } - } - $this->path = $this->getPath() . '/' . self::SQLITE_DIR; - } - - /** - * INIT NEW DB - * @param \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")'); - $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); - $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); - } - - /** - * INIT Indexing DB - * @param \PDO $db - */ - public function initIndexing(PDO $db) - { - - // delete everything before reset indexing - $dir = opendir($this->path); - while ($file = readdir($dir)) { - if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') { - unlink($this->path . '/' . $file); - } - } - - $db->exec('drop table if exists "balancing"'); - $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); - $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); - $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); - - } - - /** - * INIT Instant DB - * Return Database of Keyword - * @param $keyword - * @return int - */ - public function indexing($keyword) - { - if ($this->indexing == null) { - $createTable = false; - if (!file_exists($this->path . '/indexing')) { - $createTable = true; - } - - $PDO = new PDO("sqlite:" . $this->path . '/' . self::INDEXING_FILE); - $PDO->setAttribute(PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION); - - if ($createTable == true) { - $this->initIndexing($PDO); - } - $this->indexing = $PDO; - unset($PDO); - - $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); - $stm->execute(); - $row = $stm->fetch(PDO::FETCH_ASSOC); - if (!isset($row[ 'db' ])) { - $db = 1; - } elseif ($row[ 'db' ] <= 1) { - $db = 1; - } else { - $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); - - - if ($size > $this->max_size) { - $db = $db + 1; - } - $this->currentDB = $db; - - } - - // look for keyword - $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); - $stm->execute(array( - ':keyword' => $keyword, - )); - $row = $stm->fetch(PDO::FETCH_ASSOC); - if (isset($row[ 'db' ]) && $row[ 'db' ] != '') { - $db = $row[ 'db' ]; - } else { - /* - * Insert new to Indexing - */ - $db = $this->currentDB; - $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); - $stm->execute(array( - ':keyword' => $keyword, - ':db' => $db, - )); - } - - return $db; - } - - /** - * @param $keyword - * @param bool $reset - * @return mixed - */ - public function db($keyword, $reset = false) - { - /** - * Default is fastcache - */ - $instant = $this->indexing($keyword); - - /** - * init instant - */ - if (!isset($this->instant[ $instant ])) { - // check DB Files ready or not - $createTable = false; - if (!file_exists($this->path . '/db' . $instant) || $reset == true) { - $createTable = true; - } - $PDO = new PDO('sqlite:' . $this->path . '/db' . $instant); - $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - if ($createTable == true) { - $this->initDB($PDO); - } - - $this->instant[ $instant ] = $PDO; - unset($PDO); - - } - - return $this->instant[ $instant ]; - } - - /** - * @return bool - */ - public function checkdriver() - { - if (extension_loaded('pdo_sqlite') && is_writable($this->getPath())) { - return true; - } - $this->fallback = true; - return 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); - - if ($skipExisting == true) { - if ($in_cache == null) { - $toWrite = true; - } else { - $toWrite = false; - } - } - - if ($toWrite == true) { - try { - $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, - )); - - return true; - } catch (\PDOException $e) { - - try { - $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, - )); - } catch (PDOException $e) { - return false; - } - } - } - return false; - } - - /** - * @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->execute(array( - ':keyword' => $keyword, - )); - $row = $stm->fetch(PDO::FETCH_ASSOC); - - } catch (PDOException $e) { - try { - $stm = $this->db($keyword, true) - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); - $stm->execute(array( - ':keyword' => $keyword, - )); - $row = $stm->fetch(PDO::FETCH_ASSOC); - } catch (PDOException $e) { - return null; - } - - } - - if ($this->isExpired($row)) { - $this->deleteRow($row); - return null; - } - - if (isset($row[ 'id' ])) { - $data = $this->decode($row[ 'object' ]); - return $data; - } - - return null; - } - - /** - * @param $row - * @return bool - */ - public function isExpired($row) - { - if (isset($row[ 'exp' ]) && time() >= $row[ 'exp' ]) { - return true; - } - - return false; - } - - /** - * @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->execute(array( - ':id' => $row[ 'id' ], - ':U' => time(), - )); - } catch (PDOException $e) { - return false; - } - } - - /** - * @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->execute(array( - ':keyword' => $keyword, - ':U' => time(), - )); - } catch (PDOException $e) { - return false; - } - } - - /** - * Return total cache size + auto removed expired entries - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - $total = 0; - $optimized = 0; - - $dir = opendir($this->path); - while ($file = readdir($dir)) { - if ($file != '.' && $file != '..') { - $file_path = $this->path . "/" . $file; - $size = filesize($file_path); - $total = $total + $size; - - try { - $PDO = new PDO("sqlite:" . $file_path); - $PDO->setAttribute(PDO::ATTR_ERRMODE, - PDO::ERRMODE_EXCEPTION); - - $stm = $PDO->prepare("DELETE FROM `caching` WHERE `exp` <= :U"); - $stm->execute(array( - ':U' => date('U'), - )); - - $PDO->exec('VACUUM;'); - $size = filesize($file_path); - $optimized = $optimized + $size; - } catch (PDOException $e) { - $size = 0; - $optimized = 0; - } - - - } - } - $res[ 'size' ] = $optimized; - $res[ 'info' ] = array( - 'total before removing expired entries [bytes]' => $total, - 'optimized after removing expired entries [bytes]' => $optimized, - ); - - return $res; - } - - /** - * @param array $option - * @return void - */ - public function driver_clean($option = array()) - { - // close connection - $this->instant = array(); - $this->indexing = null; - - // delete everything before reset indexing - $dir = opendir($this->path); - while ($file = readdir($dir)) { - if ($file != '.' && $file != '..') { - unlink($this->path . '/' . $file); - } - } - } - - /** - * @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->execute(array( - ':keyword' => $keyword, - )); - $data = $stm->fetch(PDO::FETCH_ASSOC); - if ($data[ 'total' ] >= 1) { - return true; - } else { - return false; - } - } catch (PDOException $e) { - return false; - } - } -} diff --git a/lib/phpfastcache/phpFastCache/Drivers/ssdb.php b/lib/phpfastcache/phpFastCache/Drivers/ssdb.php deleted file mode 100644 index 84830cc..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/ssdb.php +++ /dev/null @@ -1,191 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; - -/** - * Class ssdb - * @package phpFastCache\Drivers - */ -class ssdb extends DriverAbstract -{ - - /** - * @var bool - */ - private $checked_ssdb = false; - - /** - * 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'); - if (class_exists('SimpleSSDB')) { - return true; - } - $this->fallback = true; - return false; - } - - - /** - * @return bool - */ - public function connectServer() - { - - $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 = !empty($server[ 'timeout' ]) ? (int)$server[ 'timeout' ] : 2000; - $this->instant = new \SimpleSSDB($host, $port, $timeout); - if (!empty($password)) { - $this->instant->auth($password); - } - $this->checked_ssdb = true; - if (!$this->instant) { - $this->fallback = true; - return false; - } else { - return true; - } - } - - return 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 ($this->connectServer()) { - if (isset($option[ 'skipExisting' ]) && $option[ 'skipExisting' ] == true) { - $x = $this->instant->get($keyword); - if ($x === false) { - return false; - } elseif (!is_null($x)) { - return true; - } - } - $value = $this->encode($value); - return $this->instant->setx($keyword, $value, $time); - } else { - return $this->backup()->set($keyword, $value, $time, $option); - } - } - - /** - * @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); - } - } - - /** - * @param $keyword - * @param array $option - */ - public function driver_delete($keyword, $option = array()) - { - if ($this->connectServer()) { - $this->instant->del($keyword); - } - } - - /** - * @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(), - ); - - return $res; - } - - return array(); - } - - /** - * @param array $option - * @return bool - */ - public function driver_clean($option = array()) - { - //Is not supported, only support command line operations - return false; - } - - /** - * @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); - } - } -} diff --git a/lib/phpfastcache/phpFastCache/Drivers/wincache.php b/lib/phpfastcache/phpFastCache/Drivers/wincache.php deleted file mode 100644 index 44a6204..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/wincache.php +++ /dev/null @@ -1,133 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; - -/** - * Class wincache - * @package phpFastCache\Drivers - */ -class wincache extends DriverAbstract -{ - - /** - * phpFastCache_wincache 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() - { - if (extension_loaded('wincache') && function_exists('wincache_ucache_set')) { - return true; - } - $this->fallback = true; - return false; - } - - - /** - * @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); - } - } - - /** - * @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); - - if ($suc == false) { - return null; - } else { - return $x; - } - } - - /** - * @param $keyword - * @param array $option - * @return bool - */ - public function driver_delete($keyword, $option = array()) - { - return wincache_ucache_delete($keyword); - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => wincache_scache_info(), - ); - return $res; - } - - /** - * @param array $option - * @return bool - */ - public function driver_clean($option = array()) - { - wincache_ucache_clear(); - return true; - } - - /** - * @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/lib/phpfastcache/phpFastCache/Drivers/xcache.php b/lib/phpfastcache/phpFastCache/Drivers/xcache.php deleted file mode 100644 index 3b2a675..0000000 --- a/lib/phpfastcache/phpFastCache/Drivers/xcache.php +++ /dev/null @@ -1,141 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\Drivers; - -use phpFastCache\Core\DriverAbstract; -use Exception; - -/** - * Class xcache - * @package phpFastCache\Drivers - */ -class xcache extends DriverAbstract -{ - - /** - * phpFastCache_xcache 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 xcache - if (extension_loaded('xcache') && function_exists('xcache_get')) { - return true; - } - $this->fallback = true; - return false; - - } - - /** - * @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 false; - } - - /** - * @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 == '') { - return null; - } - return $data; - } - - /** - * @param $keyword - * @param array $option - * @return bool - */ - public function driver_delete($keyword, $option = array()) - { - return xcache_unset($keyword); - } - - /** - * @param array $option - * @return array - */ - public function driver_stats($option = array()) - { - $res = array( - 'info' => '', - 'size' => '', - 'data' => '', - ); - - try { - $res[ 'data' ] = xcache_list(XC_TYPE_VAR, 100); - } catch (Exception $e) { - $res[ 'data' ] = array(); - } - return $res; - } - - /** - * @param array $option - * @return bool - */ - public function driver_clean($option = array()) - { - $cnt = xcache_count(XC_TYPE_VAR); - for ($i = 0; $i < $cnt; $i++) { - xcache_clear_cache(XC_TYPE_VAR, $i); - } - return true; - } - - /** - * @param $keyword - * @return bool - */ - public function driver_isExisting($keyword) - { - return xcache_isset($keyword); - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Plugins/CronClearFiles.php b/lib/phpfastcache/phpFastCache/Plugins/CronClearFiles.php deleted file mode 100644 index 11d80eb..0000000 --- a/lib/phpfastcache/phpFastCache/Plugins/CronClearFiles.php +++ /dev/null @@ -1,33 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -namespace phpFastCache\plugins; - -use phpFastCache\CacheManager; - -// Setup your cronjob to run this file every -// 30 mins - 60 mins to help clean up -// the expired files faster - -require_once (__DIR__ . "/../phpFastCache.php"); - -$setup = array( - "path" => "/your_path/to_clean/" -); - -$cache = CacheManager::Files($setup); - -// clean up expired files cache every hour -// For now only "files" drivers is supported -$cache->autoCleanExpired(3600*1); \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Util/Legacy.php b/lib/phpfastcache/phpFastCache/Util/Legacy.php deleted file mode 100644 index a1c58f0..0000000 --- a/lib/phpfastcache/phpFastCache/Util/Legacy.php +++ /dev/null @@ -1,43 +0,0 @@ -".$tmp[0]." = ".$path." BY {$allowed_path}"; - self::$stores[$index] = true; - return true; - } - } - self::$stores[$index] = false; - } else { - return self::$stores[$index]; - } - return false; - } - return true; - } -} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/phpFastCache.php b/lib/phpfastcache/phpFastCache/phpFastCache.php deleted file mode 100644 index db1f066..0000000 --- a/lib/phpfastcache/phpFastCache/phpFastCache.php +++ /dev/null @@ -1,55 +0,0 @@ - http://www.phpfastcache.com - * @author Georges.L (Geolim4) - * - */ - -use phpFastCache\CacheManager; -define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); - -if(!defined("PHPFASTCACHE_LEGACY")) { - /** - * Register Autoload - */ - spl_autoload_register(function ($entity) { - // Explode is faster than substr & strstr also more control - $module = explode('\\',$entity,2); - if ($module[0] !== 'phpFastCache') { - /** - * Not a part of phpFastCache file - * then we return here. - */ - return; - } - - $entity = str_replace('\\', '/', $module[1]); - $path = __DIR__ . '/' . $entity . '.' . PHP_EXT; - if (is_readable($path)) { - require_once $path; - } - }); - -} else { - require_once __DIR__.'/Util/Legacy.php'; -} - -/** - * phpFastCache() Full alias - * @param string $storage - * @param array $config - * @return mixed - */ -if (!function_exists("phpFastCache")) { - function phpFastCache($storage = 'auto', $config = array()) - { - return CacheManager::getInstance($storage, $config); - } -} diff --git a/lib/phpfastcache/src/autoload.php b/lib/phpfastcache/src/autoload.php new file mode 100644 index 0000000..bc2279d --- /dev/null +++ b/lib/phpfastcache/src/autoload.php @@ -0,0 +1,51 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +define('PFC_PHP_EXT', 'php'); +define('PFC_BIN_DIR', __DIR__ . '/../bin/'); + +/** + * Register Autoload + */ +spl_autoload_register(function ($entity) { + $module = explode('\\', $entity, 2); + if (!in_array($module[ 0 ], ['phpFastCache', 'Psr'])) { + /** + * Not a part of phpFastCache file + * then we return here. + */ + return; + } else if (strpos($entity, 'Psr\Cache') === 0) { + $path = PFC_BIN_DIR . 'legacy/Psr/Cache/src/' . substr(strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT; + + if (is_readable($path)) { + require_once $path; + }else{ + trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR); + } + return; + } + + $entity = str_replace('\\', '/', $entity); + $path = __DIR__ . '/' . $entity . '.' . PFC_PHP_EXT; + + if (is_readable($path)) { + require_once $path; + } +}); + +if ((!defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && class_exists('Composer\Autoload\ClassLoader')) { + trigger_error('Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.', + E_USER_WARNING); +} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/.htaccess b/lib/phpfastcache/src/phpFastCache/.htaccess similarity index 100% rename from lib/phpfastcache/phpFastCache/.htaccess rename to lib/phpfastcache/src/phpFastCache/.htaccess diff --git a/lib/phpfastcache/src/phpFastCache/Api.php b/lib/phpfastcache/src/phpFastCache/Api.php new file mode 100644 index 0000000..5b4db10 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Api.php @@ -0,0 +1,72 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache; + +/** + * Class Api + * @package phpFastCache + */ +class Api +{ + protected static $version = '1.1.3'; + + /** + * This method will returns the current + * API version, the API version will be + * updated by following the semantic versioning + * based on changes of: + * - ExtendedCacheItemPoolInterface + * - ExtendedCacheItemInterface + * + * @see http://semver.org/ + * @return string + */ + public static function getVersion() + { + return self::$version; + } + + /** + * Return the API changelog, as a string. + * @return string + */ + public static function getChangelog() + { + return << http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +namespace phpFastCache\Cache; + +use phpFastCache\Core\ExtendedCacheItemPoolTrait; +use phpFastCache\Exceptions\phpFastCacheDriverException; + +/** + * Class DriverBaseTrait + * @package phpFastCache\Cache + */ +trait DriverBaseTrait +{ + use ExtendedCacheItemPoolTrait; + + /** + * @var array default options, this will be merge to Driver's Options + */ + protected $config = []; + + /** + * @var bool + */ + protected $fallback = false; + + /** + * @var mixed Instance of driver service + */ + protected $instance; + + /** + * @param $config_name + * @param string $value + */ + public function setup($config_name, $value = '') + { + /** + * Config for class + */ + if (is_array($config_name)) { + $this->config = array_merge($this->config, $config_name); + } else { + $this->config[ $config_name ] = $value; + } + } + + /** + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** + * @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 phpFastCacheDriverException("Can't Read File", 96); + + } + while (!feof($file_handle)) { + $line = fgets($file_handle); + $string .= $line; + } + fclose($file_handle); + + return $string; + } + } + + /** + * Encode data types such as object/array + * for driver that does not support + * non-scalar value + * @param $data + * @return string + */ + protected function encode($data) + { + return serialize($data); + } + + /** + * Decode data types such as object/array + * for driver that does not support + * non-scalar value + * @param $value + * @return mixed + */ + protected function decode($value) + { + return @unserialize($value); + } + + /** + * Check phpModules or CGI + * @return bool + */ + protected function isPHPModule() + { + if (PHP_SAPI === 'apache2handler') { + return true; + } else { + if (strpos(PHP_SAPI, 'handler') !== false) { + return true; + } + } + + return false; + } + + + /** + * @param $class + * @return bool + */ + protected function isExistingDriver($class) + { + return class_exists("\\phpFastCache\\Drivers\\{$class}"); + } + + + /** + * @param $tag + * @return string + */ + protected function _getTagName($tag) + { + return "__tag__" . $tag; + } + + /** + * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item + * @return array + */ + public function driverPreWrap(ExtendedCacheItemInterface $item) + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => $item->get(), + self::DRIVER_TIME_WRAPPER_INDEX => $item->getExpirationDate(), + self::DRIVER_TAGS_WRAPPER_INDEX => $item->getTags(), + ]; + } + + /** + * @param array $wrapper + * @return mixed + */ + public function driverUnwrapData(array $wrapper) + { + return $wrapper[ self::DRIVER_DATA_WRAPPER_INDEX ]; + } + + /** + * @param array $wrapper + * @return mixed + */ + public function driverUnwrapTags(array $wrapper) + { + return $wrapper[ self::DRIVER_TAGS_WRAPPER_INDEX ]; + } + + + /** + * @param array $wrapper + * @return \DateTime + */ + public function driverUnwrapTime(array $wrapper) + { + return $wrapper[ self::DRIVER_TIME_WRAPPER_INDEX ]; + } + + /** + * @return string + */ + public function getDriverName() + { + static $driverName; + + return ($driverName ?: $driverName = ucfirst(substr(strrchr((new \ReflectionObject($this))->getNamespaceName(), '\\'), 1))); + } + + /** + * @param \phpFastCache\Cache\ExtendedCacheItemInterface $item + * @return bool + * @throws \LogicException + */ + public function driverWriteTags(ExtendedCacheItemInterface $item) + { + /** + * Do not attempt to write tags + * on tags item, it can leads + * to an infinite recursive calls + */ + if(strpos($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX ) === 0){ + throw new \LogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey()); + } + + /** + * @var $tagsItems ExtendedCacheItemInterface[] + */ + $tagsItems = $this->getItems($this->getTagKeys($item->getTags())); + + foreach ($tagsItems as $tagsItem) { + $data = $tagsItem->get(); + $expTimestamp = $item->getExpirationDate()->getTimestamp(); + + /** + * Using the key will + * avoid to use array_unique + * that has slow performances + */ + + $tagsItem->set(array_merge((array) $data, [$item->getKey() => $expTimestamp])); + + /** + * Set the expiration date + * of the $tagsItem based + * on the older $item + * expiration date + */ + if ($expTimestamp > $tagsItem->getExpirationDate()->getTimestamp()) { + $tagsItem->expiresAt($item->getExpirationDate()); + } + $this->driverWrite($tagsItem); + $tagsItem->setHit(true); + } + + /** + * Also update removed tags to + * keep the index up to date + */ + $tagsItems = $this->getItems($this->getTagKeys($item->getRemovedTags())); + + foreach ($tagsItems as $tagsItem) { + $data = (array) $tagsItem->get(); + + unset($data[ $item->getKey() ]); + $tagsItem->set($data); + + /** + * Recalculate the expiration date + * + * If the $tagsItem does not have + * any cache item references left + * then remove it from tagsItems index + */ + if (count($data)) { + $tagsItem->expiresAt(max($data)); + $this->driverWrite($tagsItem); + $tagsItem->setHit(true); + } else { + $this->deleteItem($tagsItem->getKey()); + } + } + + return true; + } + + /** + * @param $key + * @return string + */ + public function getTagKey($key) + { + return self::DRIVER_TAGS_KEY_PREFIX . $key; + } + + /** + * @param $key + * @return string + */ + public function getTagKeys(array $keys) + { + foreach ($keys as &$key) { + $key = $this->getTagKey($key); + } + + return $keys; + } + + /** + * @param string $optionName + * @param mixed $optionValue + * @return bool + * @throws \InvalidArgumentException + */ + public static function isValidOption($optionName, $optionValue) + { + if (!is_string($optionName)) { + throw new \InvalidArgumentException('$optionName must be a string'); + } + + return true; + } + + /** + * @return array + */ + public static function getRequiredOptions() + { + return []; + } + + /** + * @return array + */ + public static function getValidOptions() + { + return []; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemInterface.php b/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemInterface.php new file mode 100644 index 0000000..2ad73ee --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemInterface.php @@ -0,0 +1,170 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Cache; + +use Psr\Cache\CacheItemInterface; + +/** + * Interface ExtendedCacheItemInterface + * @package phpFastCache\Cache + */ +interface ExtendedCacheItemInterface extends CacheItemInterface, \JsonSerializable +{ + /** + * Returns the encoded key for the current cache item. + * Usually as a MD5 hash + * + * @return string + * The encoded key string for this cache item. + */ + public function getEncodedKey(); + + /** + * @return mixed + */ + public function getUncommittedData(); + + /** + * @return \DateTimeInterface + */ + public function getExpirationDate(); + + /** + * @return int + */ + public function getTtl(); + + /** + * @return bool + */ + public function isExpired(); + + /** + * @param \phpFastCache\Cache\ExtendedCacheItemPoolInterface $driver + * @return mixed + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver); + + /** + * @param bool $isHit + * @return $this + * @throws \InvalidArgumentException + */ + public function setHit($isHit); + + /** + * @param int $step + * @return $this + * @throws \InvalidArgumentException + */ + public function increment($step = 1); + + /** + * @param int $step + * @return $this + * @throws \InvalidArgumentException + */ + public function decrement($step = 1); + + /** + * @param array|string $data + * @return $this + * @throws \InvalidArgumentException + */ + public function append($data); + + /** + * @param array|string $data + * @return $this + * @throws \InvalidArgumentException + */ + public function prepend($data); + + + /** + * Sets the expiration time for this cache item. + * + * @param int|\DateInterval $time + * The period of time from the present after which the item MUST be considered + * expired. An integer parameter is understood to be the time in seconds until + * expiration. If null is passed explicitly, a default value MAY be used. + * If none is set, the value should be stored permanently or for as long as the + * implementation allows. + * + * @return static + * The called object. + * + * @deprecated Use CacheItemInterface::expiresAfter() instead + */ + public function touch($time); + + /** + * @param string $tagName + * @return $this + * @throws \InvalidArgumentException + */ + public function addTag($tagName); + + /** + * @param array $tagNames + * @return $this + */ + public function addTags(array $tagNames); + + + /** + * @param array $tags + * @return $this + * @throws \InvalidArgumentException + */ + public function setTags(array $tags); + + /** + * @return array + */ + public function getTags(); + + /** + * @param string $separator + * @return mixed + */ + public function getTagsAsString($separator = ', '); + + /** + * @param array $tagName + * @return $this + */ + public function removeTag($tagName); + + /** + * @param array $tagNames + * @return $this + */ + public function removeTags(array $tagNames); + + /** + * @return array + */ + public function getRemovedTags(); + + /** + * Return the data as a well-formatted string. + * Any scalar value will be casted to an array + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * @return string + */ + public function getDataAsJsonString($option = 0, $depth = 512); +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php b/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php new file mode 100644 index 0000000..1208918 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php @@ -0,0 +1,357 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Cache; + +use InvalidArgumentException; +use phpFastCache\Entities\driverStatistic; +use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; + +/** + * Interface ExtendedCacheItemPoolInterface + * @package phpFastCache\Cache + */ +interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface +{ + /** + * @return array + */ + public function getConfig(); + + /** + * @return string + */ + public function getDriverName(); + + + /** + * [phpFastCache phpDoc Override] + * Returns a Cache Item representing the specified key. + * + * This method must always return a CacheItemInterface object, even in case of + * a cache miss. It MUST NOT return null. + * + * @param string $key + * The key for which to return the corresponding Cache Item. + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface + * The corresponding Cache Item. + */ + public function getItem($key); + + /** + * [phpFastCache phpDoc Override] + * Returns a traversable set of cache items. + * + * @param array $keys + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItems(array $keys = []); + + /** + * Returns A json string that represents an array of items. + * + * @param array $keys + * An indexed array of keys of items to retrieve. + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return string + */ + public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + public function setItem(CacheItemInterface $item); + + /** + * Deletes all items in the pool. + * @deprecated Use clear() instead + * Will be removed in 5.1 + * + * @return bool + * True if the pool was successfully cleared. False if there was an error. + */ + public function clean(); + + /** + * @return driverStatistic + */ + public function getStats(); + + /** + * Returns a traversable set of cache items by a tag name. + * + * @param string $tagName + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItemsByTag($tagName); + + /** + * Returns a traversable set of cache items by a tag name. + * + * @param array $tagNames + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItemsByTags(array $tagNames); + + /** + * Returns A json string that represents an array of items by tags-based. + * + * @param array $tagNames + * An indexed array of keys of items to retrieve. + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return string + */ + public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512); + + /** + * Removes the item from the pool by tag. + * + * @param string $tagName + * The tag for which to delete + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully removed. False if there was an error. + */ + public function deleteItemsByTag($tagName); + + /** + * Removes the item from the pool by tag. + * + * @param array $tagNames + * The tag for which to delete + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully removed. False if there was an error. + */ + public function deleteItemsByTags(array $tagNames); + + /** + * Increment the items from the pool by tag. + * + * @param string $tagName + * The tag for which to increment + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully incremented. False if there was an error. + */ + public function incrementItemsByTag($tagName, $step = 1); + + /** + * Increment the items from the pool by tag. + * + * @param array $tagNames + * The tag for which to increment + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully incremented. False if there was an error. + */ + public function incrementItemsByTags(array $tagNames, $step = 1); + + + /** + * Decrement the items from the pool by tag. + * + * @param string $tagName + * The tag for which to decrement + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully decremented. False if there was an error. + */ + public function decrementItemsByTag($tagName, $step = 1); + + /** + * Decrement the items from the pool by tag. + * + * @param array $tagNames + * The tag for which to decrement + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully decremented. False if there was an error. + */ + public function decrementItemsByTags(array $tagNames, $step = 1); + + /** + * Decrement the items from the pool by tag. + * + * @param string $tagName + * The tag for which to append + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully appended. False if there was an error. + */ + public function appendItemsByTag($tagName, $data); + + /** + * Decrement the items from the pool by tag. + * + * @param array $tagNames + * The tag for which to append + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully appended. False if there was an error. + */ + public function appendItemsByTags(array $tagNames, $data); + + /** + * Prepend the items from the pool by tag. + * + * @param string $tagName + * The tag for which to prepend + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully prepended. False if there was an error. + */ + public function prependItemsByTag($tagName, $data); + + /** + * Prepend the items from the pool by tag. + * + * @param array $tagNames + * The tag for which to prepend + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully prepended. False if there was an error. + */ + public function prependItemsByTags(array $tagNames, $data); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + */ + public function detachItem(CacheItemInterface $item); + + /** + * @return void + */ + public function detachAllItems(); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + * @throws \LogicException + */ + public function attachItem(CacheItemInterface $item); + + /** + * Returns true if the item exists, is attached and the Spl Hash matches + * Returns false if the item exists, is attached and the Spl Hash mismatches + * Returns null if the item does not exists + * + * @param \Psr\Cache\CacheItemInterface $item + * @return bool|null + * @throws \LogicException + */ + public function isAttached(CacheItemInterface $item); +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Cache/ItemBaseTrait.php b/lib/phpfastcache/src/phpFastCache/Cache/ItemBaseTrait.php new file mode 100644 index 0000000..75deef6 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Cache/ItemBaseTrait.php @@ -0,0 +1,447 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Cache; + +use phpFastCache\Core\DriverAbstract; + +trait ItemBaseTrait +{ + /** + * @var bool + */ + protected $fetched = false; + + /** + * @var DriverAbstract + */ + protected $driver; + + /** + * @var string + */ + protected $key; + + /** + * @var mixed + */ + protected $data; + + /** + * @var \DateTime + */ + protected $expirationDate; + + /** + * @var array + */ + protected $tags = []; + + /** + * @var array + */ + protected $removedTags = []; + + /** + * @var bool + */ + protected $isHit = false; + + /******************** + * + * PSR-6 Methods + * + *******************/ + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @return mixed + */ + public function get() + { + return $this->data; + } + + /** + * @param mixed $value + * @return $this + */ + public function set($value) + { + /** + * The user set a value, + * therefore there is no need to + * fetch from source anymore + */ + $this->fetched = true; + $this->data = $value; + + return $this; + } + + /** + * @return bool + * @throws \InvalidArgumentException + */ + public function isHit() + { + return $this->isHit; + } + + /** + * @param bool $isHit + * @return $this + * @throws \InvalidArgumentException + */ + public function setHit($isHit) + { + if (is_bool($isHit)) { + $this->isHit = $isHit; + + return $this; + } else { + throw new \InvalidArgumentException('$isHit must be a boolean'); + } + } + + /** + * @param \DateTimeInterface $expiration + * @return $this + */ + public function expiresAt($expiration) + { + if ($expiration instanceof \DateTimeInterface) { + $this->expirationDate = $expiration; + } else { + throw new \InvalidArgumentException('$expiration must be an object implementing the DateTimeInterface'); + } + + return $this; + } + + /** + * Sets the expiration time for this cache item. + * + * @param int|\DateInterval $time + * The period of time from the present after which the item MUST be considered + * expired. An integer parameter is understood to be the time in seconds until + * expiration. If null is passed explicitly, a default value MAY be used. + * If none is set, the value should be stored permanently or for as long as the + * implementation allows. + * + * @return static + * The called object. + * + * @deprecated Use CacheItemInterface::expiresAfter() instead + */ + public function touch($time) + { + trigger_error('touch() is deprecated and will be removed in the next major release, use CacheItemInterface::expiresAfter() instead'); + + return $this->expiresAfter($time); + } + + /** + * @param \DateInterval|int $time + * @return $this + * @throws \InvalidArgumentException + */ + public function expiresAfter($time) + { + if (is_numeric($time)) { + if ($time <= 0) { + /** + * 5 years, however memcached or memory cached will gone when u restart it + * just recommended for sqlite. files + */ + $time = 30 * 24 * 3600 * 5; + } + $this->expirationDate = (new \DateTime())->add(new \DateInterval(sprintf('PT%dS', $time))); + } else if ($time instanceof \DateInterval) { + $this->expirationDate = (new \DateTime())->add($time); + } else { + throw new \InvalidArgumentException('Invalid date format'); + } + + return $this; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return string + */ + public function getEncodedKey() + { + return md5($this->getKey()); + } + + /** + * @return mixed + */ + public function getUncommittedData() + { + return $this->data; + } + + /** + * @return \DateTimeInterface + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @return int + */ + public function getTtl() + { + $ttl = $this->expirationDate->getTimestamp() - time(); + if ($ttl > 2592000) { + $ttl = time() + $ttl; + } + + return $ttl; + } + + /** + * @return bool + */ + public function isExpired() + { + return $this->expirationDate->getTimestamp() < (new \DateTime())->getTimestamp(); + } + + /** + * @param int $step + * @return $this + * @throws \InvalidArgumentException + */ + public function increment($step = 1) + { + if (is_int($step)) { + $this->fetched = true; + $this->data += $step; + } else { + throw new \InvalidArgumentException('$step must be numeric.'); + } + + return $this; + } + + /** + * @param int $step + * @return $this + * @throws \InvalidArgumentException + */ + public function decrement($step = 1) + { + if (is_int($step)) { + $this->fetched = true; + $this->data -= $step; + } else { + throw new \InvalidArgumentException('$step must be numeric.'); + } + + return $this; + } + + /** + * @param array|string $data + * @return $this + * @throws \InvalidArgumentException + */ + public function append($data) + { + if (is_array($this->data)) { + array_push($this->data, $data); + } else if (is_string($data)) { + $this->data .= (string) $data; + } else { + throw new \InvalidArgumentException('$data must be either array nor string.'); + } + + return $this; + } + + + /** + * @param array|string $data + * @return $this + * @throws \InvalidArgumentException + */ + public function prepend($data) + { + if (is_array($this->data)) { + array_unshift($this->data, $data); + } else if (is_string($data)) { + $this->data = (string) $data . $this->data; + } else { + throw new \InvalidArgumentException('$data must be either array nor string.'); + } + + return $this; + } + + /** + * @param $tagName + * @return $this + * @throws \InvalidArgumentException + */ + public function addTag($tagName) + { + if (is_string($tagName)) { + $this->tags = array_unique(array_merge($this->tags, [$tagName])); + + return $this; + } else { + throw new \InvalidArgumentException('$tagName must be a string'); + } + } + + /** + * @param array $tagNames + * @return $this + */ + public function addTags(array $tagNames) + { + foreach ($tagNames as $tagName) { + $this->addTag($tagName); + } + + return $this; + } + + /** + * @param array $tags + * @return $this + * @throws \InvalidArgumentException + */ + public function setTags(array $tags) + { + if (count($tags)) { + if (array_filter($tags, 'is_string')) { + $this->tags = $tags; + } else { + throw new \InvalidArgumentException('$tagName must be an array of string'); + } + } + + return $this; + } + + /** + * @return array + */ + public function getTags() + { + return $this->tags; + } + + /** + * @return string + */ + public function getTagsAsString($separator = ', ') + { + return implode($separator, $this->tags); + } + + /** + * @param $tagName + * @return $this + */ + public function removeTag($tagName) + { + if (($key = array_search($tagName, $this->tags)) !== false) { + unset($this->tags[ $key ]); + $this->removedTags[] = $tagName; + } + + return $this; + } + + /** + * @param array $tagNames + * @return $this + */ + public function removeTags(array $tagNames) + { + foreach ($tagNames as $tagName) { + $this->removeTag($tagName); + } + + return $this; + } + + /** + * @return array + */ + public function getRemovedTags() + { + return array_diff($this->removedTags, $this->tags); + } + + /** + * Return the data as a well-formatted string. + * Any scalar value will be casted to an array + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * @return string + */ + public function getDataAsJsonString($option = 0, $depth = 512) + { + $data = $this->get(); + + if (is_object($data) || is_array($data)) { + $data = json_encode($data, $option, $depth); + } else { + $data = json_encode([$data], $option, $depth); + } + + return json_encode($data, $option, $depth); + } + + /** + * Implements \JsonSerializable interface + * @return mixed + */ + public function jsonSerialize() + { + return $this->get(); + } + + /** + * Prevent recursions for Debug (php 5.6+) + * @return array + */ + final public function __debugInfo() + { + $info = get_object_vars($this); + $info[ 'driver' ] = 'object(' . get_class($info[ 'driver' ]) . ')'; + + return (array) $info; + } +} diff --git a/lib/phpfastcache/src/phpFastCache/CacheManager.php b/lib/phpfastcache/src/phpFastCache/CacheManager.php new file mode 100644 index 0000000..f9198da --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/CacheManager.php @@ -0,0 +1,270 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache; + +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; + +/** + * Class CacheManager + * @package phpFastCache + * + * @method static ExtendedCacheItemPoolInterface Apc() Apc($config = []) Return a driver "apc" instance + * @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "apcu" instance + * @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "cookie" instance + * @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "couchbase" instance + * @method static ExtendedCacheItemPoolInterface Files() Files($config = []) Return a driver "files" instance + * @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "leveldb" instance + * @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "memcache" instance + * @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "memcached" instance + * @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "mongodb" instance + * @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "predis" instance + * @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "redis" instance + * @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "sqlite" instance + * @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "ssdb" instance + * @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "wincache" instance + * @method static ExtendedCacheItemPoolInterface Xcache() Xcache($config = []) Return a driver "xcache" instance + * @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "zend disk cache" instance + * @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "zend memory cache" instance + * + */ +class CacheManager +{ + /** + * @var int + */ + public static $ReadHits = 0; + + /** + * @var int + */ + public static $WriteHits = 0; + + /** + * @var array + */ + protected static $config = [ + 'securityKey' => 'auto', // The securityKey that will be used to create the sub-directory + 'ignoreSymfonyNotice' => false, // Ignore Symfony notices for Symfony projects that do not makes use of PhpFastCache's Symfony Bundle + 'defaultTtl' => 900, // Default time-to-live in seconds + 'htaccess' => true, // Auto-generate .htaccess if it is missing + 'default_chmod' => 0777, // 0777 is recommended + 'path' => '', // If not set will be the value of sys_get_temp_dir() + 'fallback' => false, // Fall back when old driver is not supported + 'limited_memory_each_object' => 4096, // Maximum size (bytes) of object store in memory + 'compress_data' => false, // Compress stored data if the backend supports it + ]; + + /** + * @var string + */ + protected static $namespacePath; + + /** + * @var array + */ + protected static $instances = []; + + /** + * @param string $driver + * @param array $config + * @return ExtendedCacheItemPoolInterface + */ + public static function getInstance($driver = 'auto', $config = []) + { + static $badPracticeOmeter = []; + + /** + * @todo: Standardize a method for driver name + */ + $driver = self::standardizeDriverName($driver); + $config = array_merge(self::$config, $config); + if (!$driver || $driver === 'Auto') { + $driver = self::getAutoClass($config); + } + + $instance = crc32($driver . serialize($config)); + if (!isset(self::$instances[ $instance ])) { + $badPracticeOmeter[$driver] = 1; + if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){ + trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE); + } + $class = self::getNamespacePath() . $driver . '\Driver'; + try{ + self::$instances[ $instance ] = new $class($config); + }catch(phpFastCacheDriverCheckException $e){ + $fallback = self::standardizeDriverName($config['fallback']); + if($fallback && $fallback !== $driver){ + $class = self::getNamespacePath() . $fallback . '\Driver'; + self::$instances[ $instance ] = new $class($config); + trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); + }else{ + throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); + } + } + } else if(++$badPracticeOmeter[$driver] >= 5){ + trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. + See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); + } + + return self::$instances[ $instance ]; + } + + /** + * @param $config + * @return string + * @throws phpFastCacheDriverCheckException + */ + public static function getAutoClass($config = []) + { + static $autoDriver; + + if ($autoDriver === null) { + foreach (self::getStaticSystemDrivers() as $driver) { + try { + self::getInstance($driver, $config); + $autoDriver = $driver; + } catch (phpFastCacheDriverCheckException $e) { + continue; + } + } + } + + return $autoDriver; + } + + /** + * @param string $name + * @param array $arguments + * @return \Psr\Cache\CacheItemPoolInterface + */ + public static function __callStatic($name, $arguments) + { + $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []); + + return self::getInstance($name, $options); + } + + /** + * @return bool + */ + public static function clearInstances() + { + self::$instances = []; + + gc_collect_cycles(); + return !count(self::$instances); + } + + /** + * @return string + */ + public static function getNamespacePath() + { + return self::$namespacePath ?: __NAMESPACE__ . '\Drivers\\'; + } + + /** + * @param string $path + */ + public static function setNamespacePath($path) + { + self::$namespacePath = $path; + } + + /** + * @param $name + * @param string $value + * @deprecated Method "setup" is deprecated and will be removed in V6. Use method "setDefaultConfig" instead. + * @throws \InvalidArgumentException + */ + public static function setup($name, $value = '') + { + trigger_error('Method "setup" is deprecated and will be removed in V6 Use method "setDefaultConfig" instead.', E_USER_DEPRECATED); + self::setDefaultConfig($name, $value); + } + + /** + * @param $name string|array + * @param mixed $value + * @throws \InvalidArgumentException + */ + public static function setDefaultConfig($name, $value = null) + { + if (is_array($name)) { + self::$config = array_merge(self::$config, $name); + } else if (is_string($name)){ + self::$config[ $name ] = $value; + }else{ + throw new \InvalidArgumentException('Invalid variable type: $name'); + } + } + + /** + * @return array + */ + public static function getDefaultConfig() + { + return self::$config; + } + + /** + * @return array + */ + public static function getStaticSystemDrivers() + { + return [ + 'Sqlite', + 'Files', + 'Apc', + 'Apcu', + 'Memcache', + 'Memcached', + 'Couchbase', + 'Mongodb', + 'Predis', + 'Redis', + 'Ssdb', + 'Leveldb', + 'Wincache', + 'Xcache', + 'Zenddisk', + 'Zendshm', + 'Devnull', + ]; + } + + /** + * @return array + */ + public static function getStaticAllDrivers() + { + return array_merge(self::getStaticSystemDrivers(), [ + 'Devtrue', + 'Devfalse', + 'Cookie', + ]); + } + + /** + * @param string $driverName + * @return string + */ + public static function standardizeDriverName($driverName) + { + return ucfirst(strtolower(trim($driverName))); + } +} diff --git a/lib/phpfastcache/phpFastCache/Core/phpFastCacheExtensions.php b/lib/phpfastcache/src/phpFastCache/Core/ClassNamespaceResolverTrait.php similarity index 57% rename from lib/phpfastcache/phpFastCache/Core/phpFastCacheExtensions.php rename to lib/phpfastcache/src/phpFastCache/Core/ClassNamespaceResolverTrait.php index 813980f..07a72c0 100644 --- a/lib/phpfastcache/phpFastCache/Core/phpFastCacheExtensions.php +++ b/lib/phpfastcache/src/phpFastCache/Core/ClassNamespaceResolverTrait.php @@ -15,17 +15,22 @@ namespace phpFastCache\Core; /** - * Class phpFastCacheExtensions + * Trait ClassNamespaceResolverTrait * @package phpFastCache\Core */ -abstract class phpFastCacheExtensions +trait ClassNamespaceResolverTrait { /** - * @param $name - * @param $agr + * @return string */ - public function __call($name, $agr) + protected function getClassNamespace() { + static $namespace; + if (!$namespace) { + $namespace = (new \ReflectionObject($this))->getNamespaceName(); + } + + return $namespace; } } \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Core/DriverAbstract.php b/lib/phpfastcache/src/phpFastCache/Core/DriverAbstract.php new file mode 100644 index 0000000..1f8e898 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Core/DriverAbstract.php @@ -0,0 +1,67 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Core; + +use phpFastCache\Cache\DriverBaseTrait; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use Psr\Cache\CacheItemInterface; + +/** + * Class DriverAbstract + * @package phpFastCache\Core + */ +abstract class DriverAbstract implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue.'; + const DRIVER_TAGS_KEY_PREFIX = '_TAG_'; + const DRIVER_DATA_WRAPPER_INDEX = 'd'; + const DRIVER_TIME_WRAPPER_INDEX = 't'; + const DRIVER_TAGS_WRAPPER_INDEX = 'g'; + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array [ + * 'd' => 'THE ITEM DATA' + * 't' => 'THE ITEM DATE EXPIRATION' + * 'g' => 'THE ITEM TAGS' + * ] + * + */ + abstract protected function driverRead(CacheItemInterface $item); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + abstract protected function driverWrite(CacheItemInterface $item); + + /** + * @return bool + */ + abstract protected function driverClear(); + + /** + * @return bool + */ + abstract protected function driverConnect(); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + */ + abstract protected function driverDelete(CacheItemInterface $item); +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php b/lib/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php new file mode 100644 index 0000000..0d0ad9f --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php @@ -0,0 +1,370 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Core; + +use InvalidArgumentException; +use phpFastCache\Cache\ExtendedCacheItemInterface; +use Psr\Cache\CacheItemInterface; + +trait ExtendedCacheItemPoolTrait +{ + use StandardPsr6StructureTrait; + + /** + * Deletes all items in the pool. + * @deprecated Use clear() instead + * Will be removed in 5.1 + * + * @return bool + * True if the pool was successfully cleared. False if there was an error. + */ + public function clean() + { + trigger_error('Cache clean() method is deprecated, use clear() method instead', E_USER_DEPRECATED); + return $this->clear(); + } + + /** + * @param array $keys + * An indexed array of keys of items to retrieve. + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * @return string + * @throws \InvalidArgumentException + */ + public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) + { + $callback = function(CacheItemInterface $item){ + return $item->get(); + }; + return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth); + } + + /** + * @param string $tagName + * @return \phpFastCache\Cache\ExtendedCacheItemInterface[] + * @throws InvalidArgumentException + */ + public function getItemsByTag($tagName) + { + if (is_string($tagName)) { + $driverResponse = $this->getItem($this->getTagKey($tagName)); + if ($driverResponse->isHit()) { + $items = (array) $driverResponse->get(); + + /** + * getItems() may provides expired item(s) + * themselves provided by a cache of item + * keys based stored the tag item. + * Therefore we pass a filter callback + * to remove the expired Item(s) provided by + * the item keys passed through getItems() + * + * #headache + */ + return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item){ + return $item->isHit(); + }); + } else { + return []; + } + } else { + throw new InvalidArgumentException('$tagName must be a string'); + } + } + + /** + * @param array $tagNames + * @return \phpFastCache\Cache\ExtendedCacheItemInterface[] + * @throws InvalidArgumentException + */ + public function getItemsByTags(array $tagNames) + { + $items = []; + foreach (array_unique($tagNames) as $tagName) { + $items = array_merge($items, $this->getItemsByTag($tagName)); + } + + return $items; + } + + /** + * Returns A json string that represents an array of items by tags-based. + * + * @param array $tagNames + * An indexed array of keys of items to retrieve. + * @param int $option json_encode() options + * @param int $depth json_encode() depth + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException + * MUST be thrown. + * + * @return string + */ + public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) + { + $callback = function(CacheItemInterface $item){ + return $item->get(); + }; + + return json_encode(array_map($callback, array_values($this->getItemsByTags($tagNames))), $option, $depth); + } + + /** + * @param string $tagName + * @return bool|null + * @throws InvalidArgumentException + */ + public function deleteItemsByTag($tagName) + { + if (is_string($tagName)) { + $return = null; + foreach ($this->getItemsByTag($tagName) as $item) { + $result = $this->deleteItem($item->getKey()); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } else { + throw new InvalidArgumentException('$tagName must be a string'); + } + } + + /** + * @param array $tagNames + * @return bool|null + * @throws InvalidArgumentException + */ + public function deleteItemsByTags(array $tagNames) + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->deleteItemsByTag($tagName); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } + + /** + * @inheritdoc + */ + public function incrementItemsByTag($tagName, $step = 1) + { + if (is_string($tagName) && is_int($step)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->increment($step); + $this->saveDeferred($item); + } + + return $this->commit(); + } else { + throw new InvalidArgumentException('$tagName must be a string and $step an integer'); + } + } + + /** + * @inheritdoc + */ + public function incrementItemsByTags(array $tagNames, $step = 1) + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->incrementItemsByTag($tagName, $step); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } + + /** + * @inheritdoc + */ + public function decrementItemsByTag($tagName, $step = 1) + { + if (is_string($tagName) && is_int($step)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->decrement($step); + $this->saveDeferred($item); + } + + return $this->commit(); + } else { + throw new InvalidArgumentException('$tagName must be a string and $step an integer'); + } + } + + /** + * @inheritdoc + */ + public function decrementItemsByTags(array $tagNames, $step = 1) + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->decrementItemsByTag($tagName, $step); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } + + /** + * @inheritdoc + */ + public function appendItemsByTag($tagName, $data) + { + if (is_string($tagName)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->append($data); + $this->saveDeferred($item); + } + + return $this->commit(); + } else { + throw new InvalidArgumentException('$tagName must be a string'); + } + } + + /** + * @inheritdoc + */ + public function appendItemsByTags(array $tagNames, $data) + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->appendItemsByTag($tagName, $data); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } + + /** + * @inheritdoc + */ + public function prependItemsByTag($tagName, $data) + { + if (is_string($tagName)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->prepend($data); + $this->saveDeferred($item); + } + + return $this->commit(); + } else { + throw new InvalidArgumentException('$tagName must be a string'); + } + } + + /** + * @inheritdoc + */ + public function prependItemsByTags(array $tagNames, $data) + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->prependItemsByTag($tagName, $data); + if ($return !== false) { + $return = $result; + } + } + + return $return; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + */ + public function detachItem(CacheItemInterface $item) + { + if(isset($this->itemInstances[$item->getKey()])){ + $this->deregisterItem($item); + } + } + + /** + * @return void + */ + public function detachAllItems() + { + foreach ($this->itemInstances as $item) { + $this->detachItem($item); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + * @throws \LogicException + */ + public function attachItem(CacheItemInterface $item) + { + if(isset($this->itemInstances[$item->getKey()]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ + throw new \LogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.'); + }else{ + $this->itemInstances[$item->getKey()] = $item; + } + } + + + /** + * @internal This method de-register an item from $this->itemInstances + * @param CacheItemInterface|string $item + * @throws \InvalidArgumentException + */ + protected function deregisterItem($item) + { + if($item instanceof CacheItemInterface){ + unset($this->itemInstances[ $item->getKey() ]); + + }else if(is_string($item)){ + unset($this->itemInstances[ $item ]); + }else{ + throw new \InvalidArgumentException('Invalid type for $item variable'); + } + if(gc_enabled()){ + gc_collect_cycles(); + } + } + + /** + * Returns true if the item exists, is attached and the Spl Hash matches + * Returns false if the item exists, is attached and the Spl Hash mismatches + * Returns null if the item does not exists + * + * @param \Psr\Cache\CacheItemInterface $item + * @return bool|null + * @throws \LogicException + */ + public function isAttached(CacheItemInterface $item) + { + if(isset($this->itemInstances[$item->getKey()])){ + return spl_object_hash($item) === spl_object_hash($this->itemInstances[ $item->getKey() ]); + } + return null; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Core/MemcacheDriverCollisionDetectorTrait.php b/lib/phpfastcache/src/phpFastCache/Core/MemcacheDriverCollisionDetectorTrait.php new file mode 100644 index 0000000..a5477b9 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Core/MemcacheDriverCollisionDetectorTrait.php @@ -0,0 +1,40 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Core; + +use phpFastCache\Exceptions\phpFastCacheCoreException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use phpFastCache\Util\Directory; + +/** + * Trait PathSeekerTrait + * @package phpFastCache\Core\Pool\IO + * @property array $config The configuration array passed via DriverBaseTrait + */ +trait PathSeekerTrait +{ + /** + * @var array + */ + public $tmp = []; + + /** + * @param bool $readonly + * @return string + * @throws phpFastCacheDriverException + */ + public function getPath($readonly = false) + { + /** + * Get the base system temporary directory + */ + $tmp_dir = rtrim(ini_get('upload_tmp_dir') ?: sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache'; + /** + * Calculate the security key + */ + { + $securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : ''; + if (!$securityKey || $securityKey === 'auto') { + if (isset($_SERVER[ 'HTTP_HOST' ])) { + $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ]))); + } else { + $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); + } + } + if ($securityKey !== '') { + $securityKey .= '/'; + } + $securityKey = static::cleanFileName($securityKey); + } + /** + * Extends the temporary directory + * with the security key and the driver name + */ + $tmp_dir = rtrim($tmp_dir, '/') . DIRECTORY_SEPARATOR; + if (empty($this->config[ 'path' ]) || !is_string($this->config[ 'path' ])) { + $path = $tmp_dir; + } else { + $path = rtrim($this->config[ 'path' ], '/') . DIRECTORY_SEPARATOR; + } + $path_suffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName(); + $full_path = Directory::getAbsolutePath($path . $path_suffix); + $full_path_tmp = Directory::getAbsolutePath($tmp_dir . $path_suffix); + $full_path_hash = md5($full_path); + /** + * In readonly mode we only attempt + * to verify if the directory exists + * or not, if it does not then we + * return the temp dir + */ + if ($readonly === true) { + if(!@file_exists($full_path) || !@is_writable($full_path)){ + return $full_path_tmp; + } + return $full_path; + }else{ + if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) { + if (!@file_exists($full_path)) { + @mkdir($full_path, $this->setChmodAuto(), true); + }elseif (!@is_writable($full_path)) { + if (!@chmod($full_path, $this->setChmodAuto())) + { + /** + * Switch back to tmp dir + * again if the path is not writable + */ + $full_path = $full_path_tmp; + if (!@file_exists($full_path)) { + @mkdir($full_path, $this->setChmodAuto(), true); + } + } + } + + /** + * In case there is no directory + * writable including tye temporary + * one, we must throw an exception + */ + if (!@file_exists($full_path) || !@is_writable($full_path)) { + throw new phpFastCacheDriverException('PLEASE CREATE OR CHMOD ' . $full_path . ' - 0777 OR ANY WRITABLE PERMISSION!'); + } + $this->tmp[ $full_path_hash ] = $full_path; + $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config[ 'htaccess' ] : false); + } + } + return realpath($full_path); + } + + + /** + * @param $keyword + * @return string + */ + protected function encodeFilename($keyword) + { + return md5($keyword); + } + + /** + * @return bool + */ + public function isExpired() + { + trigger_error(__FUNCTION__ . '() is deprecated, use ExtendedCacheItemInterface::isExpired() instead.', E_USER_DEPRECATED); + + return true; + } + + + /** + * @return string + * @throws \phpFastCache\Exceptions\phpFastCacheCoreException + */ + public function getFileDir() + { + return $this->getPath() . DIRECTORY_SEPARATOR . self::FILE_DIR; + } + + /** + * @param $keyword + * @param bool $skip + * @return string + * @throws phpFastCacheDriverException + */ + private function getFilePath($keyword, $skip = false) + { + $path = $this->getFileDir(); + + if ($keyword === false) { + return $path; + } + + $filename = $this->encodeFilename($keyword); + $folder = substr($filename, 0, 2); + $path = rtrim($path, '/') . '/' . $folder; + /** + * Skip Create Sub Folders; + */ + if ($skip == false) { + if (!file_exists($path)) { + if (@!mkdir($path, $this->setChmodAuto(), true)) { + throw new phpFastCacheDriverException('PLEASE CHMOD ' . $this->getPath() . ' - ' . $this->setChmodAuto() . ' OR ANY WRITABLE PERMISSION!'); + } + } + } + + return $path . '/' . $filename . '.txt'; + } + + + /** + * @param $this ->config + * @return int + */ + public function setChmodAuto() + { + if (!isset($this->config[ 'default_chmod' ]) || $this->config[ 'default_chmod' ] == '' || is_null($this->config[ 'default_chmod' ])) { + return 0777; + } else { + return $this->config[ 'default_chmod' ]; + } + } + + /** + * @param $filename + * @return mixed + */ + protected static function cleanFileName($filename) + { + $regex = [ + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', + '/\.$/', + '/^\./', + ]; + $replace = ['-', '', '']; + + return trim(preg_replace($regex, $replace, trim($filename)), '-'); + } + + /** + * @param $path + * @param bool $create + * @throws \Exception + */ + protected function htaccessGen($path, $create = true) + { + if ($create === true) { + if (!is_writable($path)) { + try { + if(!chmod($path, 0777)){ + throw new phpFastCacheDriverException('Chmod failed on : ' . $path); + } + } catch (phpFastCacheDriverException $e) { + throw new phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 0, $e); + } + } + + if (!file_exists($path . "/.htaccess")) { + $html = "order deny, allow \r\n +deny from all \r\n +allow from 127.0.0.1"; + + $file = @fopen($path . '/.htaccess', 'w+'); + if (!$file) { + throw new phpFastCacheDriverException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!'); + } + fwrite($file, $html); + fclose($file); + } + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php b/lib/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php new file mode 100644 index 0000000..e57a744 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php @@ -0,0 +1,247 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Core; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\CacheManager; +use phpFastCache\Exceptions\phpFastCacheCoreException; +use Psr\Cache\CacheItemInterface; + +/** + * Trait StandardPsr6StructureTrait + * @package phpFastCache\Core + */ +trait StandardPsr6StructureTrait +{ + use ClassNamespaceResolverTrait; + + /** + * @var array + */ + protected $deferredList = []; + + /** + * @var ExtendedCacheItemInterface[] + */ + protected $itemInstances = []; + + /** + * @param string $key + * @return \phpFastCache\Cache\ExtendedCacheItemInterface + * @throws \InvalidArgumentException + * @throws phpFastCacheCoreException + */ + public function getItem($key) + { + if (is_string($key)) { + if (!array_key_exists($key, $this->itemInstances)) { + + /** + * @var $item ExtendedCacheItemInterface + */ + CacheManager::$ReadHits++; + $class = new \ReflectionClass((new \ReflectionObject($this))->getNamespaceName() . '\Item'); + $item = $class->newInstanceArgs([$this, $key]); + $driverArray = $this->driverRead($item); + + if ($driverArray) { + if(!is_array($driverArray)){ + throw new phpFastCacheCoreException(sprintf('The driverRead method returned an unexpected variable type: %s', gettype($driverArray))); + } + $item->set($this->driverUnwrapData($driverArray)); + $item->expiresAt($this->driverUnwrapTime($driverArray)); + $item->setTags($this->driverUnwrapTags($driverArray)); + if ($item->isExpired()) { + /** + * Using driverDelete() instead of delete() + * to avoid infinite loop caused by + * getItem() call in delete() method + * As we MUST return an item in any + * way, we do not de-register here + */ + $this->driverDelete($item); + + } else { + $item->setHit(true); + } + } else { + $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])); + } + + } + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + + return $this->itemInstances[ $key ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return $this + * @throws \InvalidArgumentException + */ + public function setItem(CacheItemInterface $item) + { + if ($this->getClassNamespace() . '\\Item' === get_class($item)) { + $this->itemInstances[ $item->getKey() ] = $item; + + return $this; + } else { + throw new \InvalidArgumentException(sprintf('Invalid Item Class "%s" for this driver.', get_class($item))); + } + } + + /** + * @param array $keys + * @return CacheItemInterface[] + * @throws \InvalidArgumentException + */ + public function getItems(array $keys = []) + { + $collection = []; + foreach ($keys as $key) { + $collection[ $key ] = $this->getItem($key); + } + + return $collection; + } + + /** + * @param string $key + * @return bool + * @throws \InvalidArgumentException + */ + public function hasItem($key) + { + CacheManager::$ReadHits++; + + return $this->getItem($key)->isHit(); + } + + /** + * @return bool + */ + public function clear() + { + CacheManager::$WriteHits++; + $this->itemInstances = []; + + return $this->driverClear(); + } + + /** + * @param string $key + * @return bool + * @throws \InvalidArgumentException + */ + public function deleteItem($key) + { + $item = $this->getItem($key); + if ($this->hasItem($key) && $this->driverDelete($item)) { + $item->setHit(false); + CacheManager::$WriteHits++; + /** + * De-register the item instance + * then collect gc cycles + */ + $this->deregisterItem($key); + + return true; + } + + return false; + } + + /** + * @param array $keys + * @return bool + * @throws \InvalidArgumentException + */ + public function deleteItems(array $keys) + { + $return = null; + foreach ($keys as $key) { + $result = $this->deleteItem($key); + if ($result !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + * @throws \RuntimeException + */ + public function save(CacheItemInterface $item) + { + /** + * @var ExtendedCacheItemInterface $item + */ + if (!array_key_exists($item->getKey(), $this->itemInstances)) { + $this->itemInstances[ $item->getKey() ] = $item; + } else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ + throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); + } + + + if ($this->driverWrite($item) && $this->driverWriteTags($item)) { + $item->setHit(true); + CacheManager::$WriteHits++; + + return true; + } + + return false; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return \Psr\Cache\CacheItemInterface + * @throws \RuntimeException + */ + public function saveDeferred(CacheItemInterface $item) + { + if (!array_key_exists($item->getKey(), $this->itemInstances)) { + $this->itemInstances[ $item->getKey() ] = $item; + }else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ + throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); + } + + return $this->deferredList[ $item->getKey() ] = $item; + } + + /** + * @return mixed|null + * @throws \InvalidArgumentException + */ + public function commit() + { + $return = null; + foreach ($this->deferredList as $key => $item) { + $result = $this->save($item); + if ($return !== false) { + unset($this->deferredList[ $key ]); + $return = $result; + } + } + + return (bool) $return; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Driver.php new file mode 100644 index 0000000..d7013ac --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Driver.php @@ -0,0 +1,143 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Apc; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (extension_loaded('apc') && ini_get('apc.enabled')) { + return true; + } else { + return false; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return apc_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $data = apc_fetch($item->getKey(), $success); + if ($success === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return apc_delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return @apc_clear_cache() && @apc_clear_cache('user'); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stats = (array) apc_cache_info('user'); + $date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("The APC cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), + $stats[ 'num_entries' ])) + ->setRawData($stats) + ->setSize($stats[ 'mem_size' ]); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Item.php new file mode 100644 index 0000000..fa37b14 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Apc/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Apc; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Apc\Driver as ApcDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Apc\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(ApcDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ApcDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Driver.php new file mode 100644 index 0000000..428cef4 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Driver.php @@ -0,0 +1,142 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Apcu; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (extension_loaded('apcu') && ini_get('apc.enabled')) { + return true; + } else { + return false; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return apcu_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $data = apcu_fetch($item->getKey(), $success); + if ($success === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return apcu_delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return @apcu_clear_cache() && @apcu_clear_cache('user'); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stats = (array) apcu_cache_info('user'); + $date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), $stats[ 'num_entries' ])) + ->setRawData($stats) + ->setSize($stats[ 'mem_size' ]); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Item.php new file mode 100644 index 0000000..34b6b9c --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Apcu/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Apcu; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Apcu\Driver as ApcuDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apcu + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Apcu\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(ApcuDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ApcuDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Driver.php new file mode 100644 index 0000000..9d006c5 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Driver.php @@ -0,0 +1,197 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Cookie; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + const PREFIX = 'PFC_'; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (function_exists('setcookie')) { + return true; + } else { + return false; + } + } + + /** + * @return bool + */ + protected function driverConnect() + { + return !(!array_key_exists('phpFastCache', $_COOKIE) && !@setcookie('phpFastCache', 1, 10)); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->driverConnect(); + $keyword = self::PREFIX . $item->getKey(); + $v = json_encode($this->driverPreWrap($item)); + + if (isset($this->config[ 'limited_memory_each_object' ]) && strlen($v) > $this->config[ 'limited_memory_each_object' ]) { + return false; + } + + return setcookie($keyword, $v, $item->getExpirationDate()->getTimestamp(), '/'); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \phpFastCache\Exceptions\phpFastCacheDriverException + */ + protected function driverRead(CacheItemInterface $item) + { + $this->driverConnect(); + // return null if no caching + // return value if in caching + $keyword = self::PREFIX . $item->getKey(); + $x = isset($_COOKIE[ $keyword ]) ? json_decode($_COOKIE[ $keyword ], true) : false; + + if ($x == false) { + return null; + } else { + if (!is_scalar($this->driverUnwrapData($x)) && !is_null($this->driverUnwrapData($x))) { + throw new phpFastCacheDriverException('Hacking attempt: The decoding returned a non-scalar value, Cookie driver does not allow this.'); + } + + return $x; + } + } + + /** + * @param $key + * @return int + */ + protected function driverReadExpirationDate($key) + { + $this->driverConnect(); + $keyword = self::PREFIX . $key; + $x = isset($_COOKIE[ $keyword ]) ? $this->decode(json_decode($_COOKIE[ $keyword ])->t) : false; + + return $x ? $x - time() : $x; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->driverConnect(); + $keyword = self::PREFIX . $item->getKey(); + $_COOKIE[ $keyword ] = null; + + return @setcookie($keyword, null, -10); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + $return = null; + $this->driverConnect(); + foreach ($_COOKIE as $keyword => $value) { + if (strpos($keyword, self::PREFIX) !== false) { + $_COOKIE[ $keyword ] = null; + $result = @setcookie($keyword, null, -10); + if ($return !== false) { + $return = $result; + } + } + } + + return $return; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $size = 0; + $stat = new driverStatistic(); + $stat->setData($_COOKIE); + + /** + * Only count PFC Cookie + */ + foreach ($_COOKIE as $key => $value) { + if (strpos($key, self::PREFIX) === 0) { + $size += strlen($value); + } + } + + $stat->setSize($size); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Item.php new file mode 100644 index 0000000..8a07492 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Cookie/Item.php @@ -0,0 +1,65 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Cookie; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Cookie\Driver as CookieDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Cookie\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(CookieDriver $driver, $key) + { + if (is_string($key)) { + $this->expirationDate = new \DateTime(); + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', + gettype($key))); + } + } + + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CookieDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Driver.php new file mode 100644 index 0000000..109127a --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Driver.php @@ -0,0 +1,199 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Couchbase; + +use CouchbaseCluster as CouchbaseClient; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * @var CouchbaseClient + */ + public $instance; + + /** + * @var \CouchbaseBucket[] + */ + protected $bucketInstances = []; + + /** + * @var string + */ + protected $bucketCurrent = ''; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->driverConnect(); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('Couchbase'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->getBucket()->upsert($item->getKey(), $this->encode($this->driverPreWrap($item)), ['expiry' => $item->getTtl()]); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + try { + /** + * CouchbaseBucket::get() returns a CouchbaseMetaDoc object + */ + return $this->decode($this->getBucket()->get($item->getKey())->value); + } catch (\CouchbaseException $e) { + return null; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->getBucket()->remove($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->getBucket()->manager()->flush(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + if ($this->instance instanceof CouchbaseClient) { + throw new \LogicException('Already connected to Couchbase server'); + } else { + + + $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; + //$port = isset($server[ 'port' ]) ? $server[ 'port' ] : '11211'; + $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; + $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; + $buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [ + [ + 'bucket' => 'default', + 'password' => '', + ], + ]; + + $this->instance = $this->instance ?: new CouchbaseClient("couchbase://{$host}", $username, $password); + + foreach ($buckets as $bucket) { + $this->bucketCurrent = $this->bucketCurrent ?: $bucket[ 'bucket' ]; + $this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ], $bucket[ 'password' ])); + } + } + } + + /** + * @return \CouchbaseBucket + */ + protected function getBucket() + { + return $this->bucketInstances[ $this->bucketCurrent ]; + } + + /** + * @param $bucketName + * @param \CouchbaseBucket $CouchbaseBucket + * @throws \LogicException + */ + protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket) + { + if (!array_key_exists($bucketName, $this->bucketInstances)) { + $this->bucketInstances[ $bucketName ] = $CouchbaseBucket; + } else { + throw new \LogicException('A bucket instance with this name already exists.'); + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $info = $this->getBucket()->manager()->info(); + + return (new driverStatistic()) + ->setSize($info[ 'basicStats' ][ 'diskUsed' ]) + ->setRawData($info) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData."); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Item.php new file mode 100644 index 0000000..032ab81 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Couchbase/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Couchbase; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Couchbase\Driver as CouchbaseDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Couchbase\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(CouchbaseDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CouchbaseDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Driver.php new file mode 100644 index 0000000..44a701a --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Driver.php @@ -0,0 +1,136 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devfalse; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array [ + * 'd' => 'THE ITEM DATA' + * 't' => 'THE ITEM DATE EXPIRATION' + * 'g' => 'THE ITEM TAGS' + * ] + */ + protected function driverRead(CacheItemInterface $item) + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => false, + self::DRIVER_TAGS_WRAPPER_INDEX => [], + self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), + ]; + } + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return true; + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stat = new driverStatistic(); + $stat->setInfo('[Devfalse] A void info string') + ->setSize(0) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData(false); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Item.php new file mode 100644 index 0000000..e3c7ffb --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devfalse/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devfalse; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Devnull\Driver as DevnullDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Devnull + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Devnull\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(DevnullDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevnullDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Driver.php new file mode 100644 index 0000000..6a038de --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Driver.php @@ -0,0 +1,138 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devnull; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array [ + * 'd' => 'THE ITEM DATA' + * 't' => 'THE ITEM DATE EXPIRATION' + * 'g' => 'THE ITEM TAGS' + * ] + */ + protected function driverRead(CacheItemInterface $item) + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => null, + self::DRIVER_TAGS_WRAPPER_INDEX => [], + self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), + ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return true; + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stat = new driverStatistic(); + $stat->setInfo('[Devnull] A void info string') + ->setSize(0) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData(null); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Item.php new file mode 100644 index 0000000..3a6581b --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devnull/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devnull; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Devnull\Driver as DevnullDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Devnull + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Devnull\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(DevnullDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevnullDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Driver.php new file mode 100644 index 0000000..2d6385b --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Driver.php @@ -0,0 +1,138 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devtrue; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return false; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array [ + * 'd' => 'THE ITEM DATA' + * 't' => 'THE ITEM DATE EXPIRATION' + * 'g' => 'THE ITEM TAGS' + * ] + */ + protected function driverRead(CacheItemInterface $item) + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => true, + self::DRIVER_TAGS_WRAPPER_INDEX => [], + self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), + ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return false; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return false; + } + + /** + * @return bool + */ + protected function driverConnect() + { + return false; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stat = new driverStatistic(); + $stat->setInfo('[Devtrue] A void info string') + ->setSize(0) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData(true); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Item.php new file mode 100644 index 0000000..936fab0 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Devtrue/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Devtrue; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Devtrue\Driver as DevtrueDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Devtrue + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Devtrue\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(DevtrueDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevtrueDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php new file mode 100644 index 0000000..521185e --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php @@ -0,0 +1,239 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Files; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\PathSeekerTrait; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use phpFastCache\Util\Directory; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + use PathSeekerTrait; + + /** + * + */ + const FILE_DIR = 'files'; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return is_writable($this->getFileDir()) || @mkdir($this->getFileDir(), $this->setChmodAuto(), true); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $file_path = $this->getFilePath($item->getKey()); + $data = $this->encode($this->driverPreWrap($item)); + + $toWrite = true; + + /** + * Skip if Existing Caching in Options + */ + if (isset($this->config[ 'skipExisting' ]) && $this->config[ 'skipExisting' ] == true && file_exists($file_path)) { + $content = $this->readfile($file_path); + $old = $this->decode($content); + $toWrite = false; + if ($old->isExpired()) { + $toWrite = true; + } + } + + /** + * Force write + */ + try { + if ($toWrite == true) { + $f = fopen($file_path, 'w+'); + fwrite($f, $data); + fclose($f); + + return true; + } + } catch (\Exception $e) { + return false; + } + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + $file_path = $this->getFilePath($item->getKey()); + if (!file_exists($file_path)) { + return null; + } + + $content = $this->readfile($file_path); + + return $this->decode($content); + + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $file_path = $this->getFilePath($item->getKey(), true); + if (file_exists($file_path) && @unlink($file_path)) { + return true; + } else { + return false; + } + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return (bool) Directory::rrmdir($this->getPath(true)); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /** + * @param string $optionName + * @param mixed $optionValue + * @return bool + * @throws \InvalidArgumentException + */ + public static function isValidOption($optionName, $optionValue) + { + parent::isValidOption($optionName, $optionValue); + switch ($optionName) { + case 'path': + return is_string($optionValue); + break; + + case 'default_chmod': + return is_numeric($optionValue); + break; + + case 'securityKey': + return is_string($optionValue); + break; + case 'htaccess': + return is_bool($optionValue); + break; + default: + return false; + break; + } + } + + /** + * @return array + */ + public static function getValidOptions() + { + return ['path', 'default_chmod', 'securityKey', 'htaccess']; + } + + /** + * @return array + */ + public static function getRequiredOptions() + { + return ['path']; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + * @throws \phpFastCache\Exceptions\phpFastCacheCoreException + * @throws \phpFastCache\Exceptions\phpFastCacheDriverException + */ + public function getStats() + { + $stat = new driverStatistic(); + $path = $this->getFilePath(false); + + if (!is_dir($path)) { + throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94); + } + + $stat->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData([]) + ->setSize(Directory::dirSize($path)) + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Files/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Files/Item.php new file mode 100644 index 0000000..7ee6b6b --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Files/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Files; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Files\Driver as FilesDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Files\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(FilesDriver $driver, $key) + { + if (is_string($key)) { + $this->expirationDate = new \DateTime(); + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', get_class($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof FilesDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Driver.php new file mode 100644 index 0000000..56afb58 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Driver.php @@ -0,0 +1,177 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Leveldb; + +use LevelDB as LeveldbClient; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\PathSeekerTrait; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use phpFastCache\Util\Directory; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + use PathSeekerTrait; + + const LEVELDB_FILENAME = '.database'; + + /** + * @var LeveldbClient Instance of driver service + */ + public $instance; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->driverConnect(); + } + } + + /** + * @return string + * @throws \phpFastCache\Exceptions\phpFastCacheCoreException + */ + public function getLeveldbFile() + { + return $this->getPath() . '/' . self::LEVELDB_FILENAME; + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('Leveldb'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->set($item->getKey(), $this->encode($this->driverPreWrap($item))); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } else { + return $this->decode($val); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + if ($this->instance instanceof LeveldbClient) { + $this->instance->close(); + $this->instance = null; + } + $result = LeveldbClient::destroy($this->getLeveldbFile()); + $this->driverConnect(); + + return $result; + } + + /** + * @return bool + */ + protected function driverConnect() + { + if ($this->instance instanceof LeveldbClient) { + throw new \LogicException('Already connected to Leveldb database'); + } else { + $this->instance = $this->instance ?: new LeveldbClient($this->getLeveldbFile()); + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($this->getLeveldbFile())) + ->setSize(Directory::dirSize($this->getLeveldbFile())); + } + + /** + * Close connection on destruct + */ + public function __destruct() + { + if ($this->instance instanceof LeveldbClient) { + $this->instance->close(); + $this->instance = null; + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Item.php new file mode 100644 index 0000000..479da7a --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Leveldb/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Leveldb; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Leveldb\Driver as LeveldbDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Leveldb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Leveldb\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(LeveldbDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof LeveldbDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Driver.php new file mode 100644 index 0000000..5511a7f --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Driver.php @@ -0,0 +1,176 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Memcache; + +use Memcache as MemcacheSoftware; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\MemcacheDriverCollisionDetectorTrait; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + use MemcacheDriverCollisionDetectorTrait; + + /** + * @var int + */ + protected $memcacheFlags = 0; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + self::checkCollision('Memcache'); + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->instance = new MemcacheSoftware(); + $this->driverConnect(); + + if (array_key_exists('compress_data', $config) && $config[ 'compress_data' ] === true) { + $this->memcacheFlags = MEMCACHE_COMPRESSED; + } + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return class_exists('Memcache'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $this->memcacheFlags, $item->getTtl()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + + if ($val === false) { + return null; + } else { + return $val; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->instance->flush(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + $servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []); + if (count($servers) < 1) { + $servers = [ + ['127.0.0.1', 11211], + ]; + } + + foreach ($servers as $server) { + try { + if (!$this->instance->addserver($server[ 0 ], $server[ 1 ])) { + $this->fallback = true; + } + if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){ + $this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password']); + } + } catch (\Exception $e) { + $this->fallback = true; + } + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stats = (array) $this->instance->getstats(); + $stats[ 'uptime' ] = (isset($stats[ 'uptime' ]) ? $stats[ 'uptime' ] : 0); + $stats[ 'version' ] = (isset($stats[ 'version' ]) ? $stats[ 'version' ] : 'UnknownVersion'); + $stats[ 'bytes' ] = (isset($stats[ 'bytes' ]) ? $stats[ 'version' ] : 0); + + $date = (new \DateTime())->setTimestamp(time() - $stats[ 'uptime' ]); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats[ 'version' ], $date->format(DATE_RFC2822))) + ->setRawData($stats) + ->setSize($stats[ 'bytes' ]); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Item.php new file mode 100644 index 0000000..6b595b6 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Memcache/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Memcache; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Memcache\Driver as MemcacheDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Memcache\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(MemcacheDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MemcacheDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Driver.php new file mode 100644 index 0000000..61cb639 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Driver.php @@ -0,0 +1,175 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Memcached; + +use Memcached as MemcachedSoftware; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\MemcacheDriverCollisionDetectorTrait; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + use MemcacheDriverCollisionDetectorTrait; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + self::checkCollision('Memcached'); + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->instance = new MemcachedSoftware(); + $this->driverConnect(); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return class_exists('Memcached'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + // Memcache will only allow a expiration timer less than 2592000 seconds, + // otherwise, it will assume you're giving it a UNIX timestamp. + if ($ttl > 2592000) { + $ttl = time() + $ttl; + } + + return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + + if ($val === false) { + return null; + } else { + return $val; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->instance->flush(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + $servers = (!empty($this->config[ 'memcache' ]) && is_array($this->config[ 'memcache' ]) ? $this->config[ 'memcache' ] : []); + if (count($servers) < 1) { + $servers = [ + ['127.0.0.1', 11211], + ]; + } + + foreach ($servers as $server) { + try { + if (!$this->instance->addServer($server[ 0 ], $server[ 1 ])) { + $this->fallback = true; + } + if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){ + $this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password']); + } + } catch (\Exception $e) { + $this->fallback = true; + } + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stats = (array) $this->instance->getStats(); + $stats[ 'uptime' ] = (isset($stats[ 'uptime' ]) ? $stats[ 'uptime' ] : 0); + $stats[ 'version' ] = (isset($stats[ 'version' ]) ? $stats[ 'version' ] : 'UnknownVersion'); + $stats[ 'bytes' ] = (isset($stats[ 'bytes' ]) ? $stats[ 'version' ] : 0); + + $date = (new \DateTime())->setTimestamp(time() - $stats[ 'uptime' ]); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats[ 'version' ], $date->format(DATE_RFC2822))) + ->setRawData($stats) + ->setSize($stats[ 'bytes' ]); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Item.php new file mode 100644 index 0000000..b479454 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Memcached/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Memcached; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Memcached\Driver as MemcachedDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Memcache\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(MemcachedDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MemcachedDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Driver.php new file mode 100644 index 0000000..3884003 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Driver.php @@ -0,0 +1,223 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Mongodb; + +use LogicException; +use MongoBinData; +use MongoClient as MongodbClient; +use MongoCollection; +use MongoConnectionException; +use MongoCursorException; +use MongoDate; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * @var MongodbClient + */ + public $instance; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->driverConnect(); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if(class_exists('MongoDB\Driver\Manager')){ + trigger_error('PhpFastCache currently only support the pecl Mongo extension.
+ The Support for the MongoDB extension will be added coming soon.', E_USER_ERROR); + } + + return extension_loaded('Mongodb') && class_exists('MongoClient'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $result = (array) $this->getCollection()->update( + ['_id' => $item->getKey()], + [ + '$set' => [ + self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), + self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), + self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), + ], + ], + ['upsert' => true, 'multiple' => false] + ); + } catch (MongoCursorException $e) { + return false; + } + + return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $document = $this->getCollection() + ->findOne(['_id' => $item->getKey()], + [self::DRIVER_DATA_WRAPPER_INDEX, self::DRIVER_TIME_WRAPPER_INDEX, self::DRIVER_TAGS_WRAPPER_INDEX /*'d', 'e'*/]); + + if ($document) { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), + self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec), + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), + ]; + } else { + return null; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $deletionResult = (array) $this->getCollection()->remove(['_id' => $item->getKey()], ["w" => 1]); + + return (int) $deletionResult[ 'ok' ] === 1 && !$deletionResult[ 'err' ]; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return (bool) $this->getCollection()->drop()['ok']; + } + + /** + * @return bool + * @throws MongoConnectionException + * @throws LogicException + */ + protected function driverConnect() + { + if ($this->instance instanceof MongodbClient) { + throw new LogicException('Already connected to Mongodb server'); + } else { + $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; + $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017'; + $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 3; + $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; + $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; + + + /** + * @todo make an url builder + */ + $this->instance = $this->instance ?: (new MongodbClient('mongodb://' . + ($username ?: '') . + ($password ? ":{$password}" : '') . + ($username ? '@' : '') . "{$host}" . + ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache; + // $this->instance->Cache->createIndex([self::DRIVER_TIME_WRAPPER_INDEX => 1], ['expireAfterSeconds' => 0]); + } + } + + + /** + * @return \MongoCollection + */ + protected function getCollection() + { + return $this->instance->Cache; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $serverStatus = $this->getCollection()->db->command([ + 'serverStatus' => 1, + 'recordStats' => 0, + 'repl' => 0, + 'metrics' => 0, + ]); + + $collStats = $this->getCollection()->db->command([ + 'collStats' => 'Cache', + 'verbose' => true, + ]); + + $stats = (new driverStatistic()) + ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") + ->setSize((int) @$collStats[ 'size' ]) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData([ + 'serverStatus' => $serverStatus, + 'collStats' => $collStats, + ]); + + return $stats; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Item.php new file mode 100644 index 0000000..b5fdd48 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Mongodb/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Mongodb; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Mongodb\Driver as MongodbDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Mongodb\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(MongodbDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MongodbDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Driver.php new file mode 100644 index 0000000..1ab5a0e --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Driver.php @@ -0,0 +1,161 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Predis; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Predis\Client as PredisClient; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * @var PredisClient Instance of driver service + */ + public $instance; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->driverConnect(); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (extension_loaded('Redis')) { + trigger_error('The native Redis extension is installed, you should use Redis instead of Predis to increase performances', E_USER_NOTICE); + } + + return class_exists('Predis\Client'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item))); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } else { + return $this->decode($val); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->del($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->instance->flushDB(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + $config = isset($this->config[ 'predis' ]) ? $this->config[ 'predis' ] : []; + + $this->instance = new PredisClient(array_merge([ + 'host' => '127.0.0.1', + 'port' => 6379, + 'password' => null, + 'database' => null, + ], $config)); + + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $info = $this->instance->info(); + $size = (isset($info['Memory']['used_memory']) ? $info['Memory']['used_memory'] : 0); + $version = (isset($info['Server']['redis_version']) ? $info['Server']['redis_version'] : 0); + $date = (isset($info['Server'][ 'uptime_in_seconds' ]) ? (new \DateTime())->setTimestamp(time() - $info['Server'][ 'uptime_in_seconds' ]) : 'unknown date'); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData($this->instance->info()) + ->setSize($size) + ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $version, $date->format(DATE_RFC2822))); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Item.php new file mode 100644 index 0000000..2c20070 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Predis/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Predis; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Predis\Driver as PredisDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Apc\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(PredisDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof PredisDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Driver.php new file mode 100644 index 0000000..adeede2 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Driver.php @@ -0,0 +1,165 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Redis; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; +use Redis as RedisClient; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + $this->driverConnect(); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('Redis'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item))); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } else { + return $this->decode($val); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->del($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->instance->flushDB(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + if ($this->instance instanceof RedisClient) { + throw new \LogicException('Already connected to Redis server'); + } else { + $this->instance = $this->instance ?: new RedisClient(); + + $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; + $port = isset($this->config[ 'port' ]) ? (int) $this->config[ 'port' ] : '6379'; + $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; + $database = isset($this->config[ 'database' ]) ? $this->config[ 'database' ] : ''; + $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : ''; + + if (!$this->instance->connect($host, (int) $port, (int) $timeout)) { + return false; + } else { + if ($password && !$this->instance->auth($password)) { + return false; + } + if ($database) { + $this->instance->select((int) $database); + } + + return true; + } + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + // used_memory + $info = $this->instance->info(); + $date = (new \DateTime())->setTimestamp(time() - $info[ 'uptime_in_seconds' ]); + + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData($info) + ->setSize($info[ 'used_memory' ]) + ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info[ 'redis_version' ], $date->format(DATE_RFC2822))); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Item.php new file mode 100644 index 0000000..e20355c --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Redis/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Redis; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Redis\Driver as RedisDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Redis + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Redis\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(RedisDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof RedisDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Driver.php new file mode 100644 index 0000000..520d637 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Driver.php @@ -0,0 +1,431 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Sqlite; + +use PDO; +use PDOException; +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\PathSeekerTrait; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use phpFastCache\Util\Directory; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + use PathSeekerTrait; + + /** + * + */ + const FILE_DIR = 'sqlite'; + /** + * + */ + const INDEXING_FILE = 'indexing'; + + /** + * @var int + */ + protected $maxSize = 10; // 10 mb + + /** + * @var int + */ + protected $currentDB = 1; + + /** + * @var string + */ + protected $SqliteDir = ''; + + /** + * @var \PDO + */ + protected $indexing; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } else { + if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->setChmodAuto(), true)) { + throw new phpFastCacheDriverException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); + } else { + $this->driverConnect(); + } + } + } + + /** + * @return string + * @throws \phpFastCache\Exceptions\phpFastCacheCoreException + */ + public function getSqliteDir() + { + return $this->SqliteDir ?: $this->getPath() . DIRECTORY_SEPARATOR . self::FILE_DIR; + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->setChmodAuto(), true)); + } + + /** + * INIT NEW DB + * @param \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")'); + $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); + $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); + } + + /** + * INIT Indexing DB + * @param \PDO $db + */ + public function initIndexing(\PDO $db) + { + + // delete everything before reset indexing + $dir = opendir($this->SqliteDir); + while ($file = readdir($dir)) { + if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') { + unlink($this->SqliteDir . '/' . $file); + } + } + + $db->exec('drop table if exists "balancing"'); + $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); + $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); + $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); + + } + + /** + * INIT Instant DB + * Return Database of Keyword + * @param $keyword + * @return int + */ + public function indexing($keyword) + { + if ($this->indexing == null) { + $createTable = false; + if (!file_exists($this->SqliteDir . '/indexing')) { + $createTable = true; + } + + $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); + $PDO->setAttribute(PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION); + + if ($createTable == true) { + $this->initIndexing($PDO); + } + $this->indexing = $PDO; + unset($PDO); + + $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); + $stm->execute(); + $row = $stm->fetch(PDO::FETCH_ASSOC); + if (!isset($row[ 'db' ])) { + $db = 1; + } elseif ($row[ 'db' ] <= 1) { + $db = 1; + } else { + $db = $row[ 'db' ]; + } + + // check file size + + $size = file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1; + $size = round($size / 1024 / 1024, 1); + + + if ($size > $this->maxSize) { + $db++; + } + $this->currentDB = $db; + + } + + // look for keyword + $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $keyword, + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + if (isset($row[ 'db' ]) && $row[ 'db' ] != '') { + $db = $row[ 'db' ]; + } else { + /* + * Insert new to Indexing + */ + $db = $this->currentDB; + $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); + $stm->execute([ + ':keyword' => $keyword, + ':db' => $db, + ]); + } + + return $db; + } + + /** + * @param $keyword + * @param bool $reset + * @return PDO + */ + public function getDb($keyword, $reset = false) + { + /** + * Default is fastcache + */ + $instant = $this->indexing($keyword); + + /** + * init instant + */ + if (!isset($this->instance[ $instant ])) { + // check DB Files ready or not + $createTable = false; + if (!file_exists($this->SqliteDir . '/db' . $instant) || $reset == true) { + $createTable = true; + } + $PDO = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant); + $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + if ($createTable == true) { + $this->initDB($PDO); + } + + $this->instance[ $instant ] = $PDO; + unset($PDO); + + } + + return $this->instance[ $instant ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $skipExisting = isset($this->config[ 'skipExisting' ]) ? $this->config[ 'skipExisting' ] : false; + $toWrite = true; + + // check in cache first + $in_cache = $this->driverRead($item); + + if ($skipExisting == true) { + if ($in_cache == null) { + $toWrite = true; + } else { + $toWrite = false; + } + } + + if ($toWrite == true) { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); + $stm->execute([ + ':keyword' => $item->getKey(), + ':object' => $this->encode($this->driverPreWrap($item)), + ':exp' => time() + $item->getTtl(), + ]); + + return true; + } catch (\PDOException $e) { + + try { + $stm = $this->getDb($item->getKey(), true) + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); + $stm->execute([ + ':keyword' => $item->getKey(), + ':object' => $this->encode($this->driverPreWrap($item)), + ':exp' => time() + $item->getTtl(), + ]); + } catch (PDOException $e) { + return false; + } + } + } + + return false; + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $item->getKey(), + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + + } catch (PDOException $e) { + try { + $stm = $this->getDb($item->getKey(), true) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $item->getKey(), + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + return null; + } + } + + if (isset($row[ 'object' ])) { + return $this->decode($row[ 'object' ]); + } + + return null; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); + + return $stm->execute([ + ':keyword' => $item->getKey(), + ':U' => time(), + ]); + } catch (PDOException $e) { + return false; + } + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + $this->instance = []; + $this->indexing = null; + + // delete everything before reset indexing + $dir = opendir($this->getSqliteDir()); + while ($file = readdir($dir)) { + if ($file != '.' && $file != '..') { + unlink($this->getSqliteDir() . '/' . $file); + } + } + + return true; + } + + /** + * @return bool + */ + protected function driverConnect() + { + if (!file_exists($this->getPath() . '/' . self::FILE_DIR)) { + if (!mkdir($this->getPath() . '/' . self::FILE_DIR, $this->setChmodAuto(), true) + ) { + $this->fallback = true; + } + } + $this->SqliteDir = $this->getPath() . '/' . self::FILE_DIR; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + * @throws PDOException + */ + public function getStats() + { + $stat = new driverStatistic(); + $path = $this->getFilePath(false); + + if (!is_dir($path)) { + throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94); + } + + $stat->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData([]) + ->setSize(Directory::dirSize($path)) + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); + + return $stat; + } + + /** + * @return array + */ + public function __sleep() + { + return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Item.php new file mode 100644 index 0000000..bc4a31b --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Sqlite/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Sqlite; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Sqlite\Driver as SqliteDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Sqlite + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Sqlite\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(SqliteDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof SqliteDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Driver.php new file mode 100644 index 0000000..5651fad --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Driver.php @@ -0,0 +1,181 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Ssdb; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use phpssdb\Core\SimpleSSDB; +use phpssdb\Core\SSDB; +use phpssdb\Core\SSDBException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * @var SimpleSSDB + */ + public $instance; + + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } elseif (!$this->driverConnect()) { + throw new phpFastCacheDriverException('Ssdb is not connected, cannot continue.'); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + static $driverCheck; + if ($driverCheck === null) { + return ($driverCheck = class_exists('phpssdb\Core\SSDB')); + } + + return $driverCheck; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->setx($item->getEncodedKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getEncodedKey()); + if ($val == false) { + return null; + } else { + return $this->decode($val); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->del($item->getEncodedKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return $this->instance->flushdb('kv'); + } + + /** + * @return bool + * @throws phpFastCacheDriverException + */ + protected function driverConnect() + { + try { + $server = isset($this->config[ 'ssdb' ]) ? $this->config[ 'ssdb' ] : [ + 'host' => "127.0.0.1", + 'port' => 8888, + 'password' => '', + 'timeout' => 2000, + ]; + + $host = $server[ 'host' ]; + $port = isset($server[ 'port' ]) ? (int) $server[ 'port' ] : 8888; + $password = isset($server[ 'password' ]) ? $server[ 'password' ] : ''; + $timeout = !empty($server[ 'timeout' ]) ? (int) $server[ 'timeout' ] : 2000; + $this->instance = new SimpleSSDB($host, $port, $timeout); + if (!empty($password)) { + $this->instance->auth($password); + } + + if (!$this->instance) { + return false; + } else { + return true; + } + } catch (SSDBException $e) { + throw new phpFastCacheDriverCheckException('Ssdb failed to connect with error: ' . $e->getMessage(), 0, $e); + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stat = new driverStatistic(); + $info = $this->instance->info(); + + /** + * Data returned by Ssdb are very poorly formatted + * using hardcoded offset of pair key-value :-( + */ + $stat->setInfo(sprintf("Ssdb-server v%s with a total of %s call(s).\n For more information see RawData.", $info[ 2 ], $info[ 6 ])) + ->setRawData($info) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setSize($this->instance->dbsize()); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Item.php new file mode 100644 index 0000000..e665061 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Ssdb/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Ssdb; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Ssdb\Driver as SsdbDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Ssdb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Ssdb\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(SsdbDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof SsdbDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Driver.php new file mode 100644 index 0000000..16b05bc --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Driver.php @@ -0,0 +1,138 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Wincache; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('wincache') && function_exists('wincache_ucache_set'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $val = wincache_ucache_get($item->getKey(), $suc); + + if ($suc === false) { + return null; + } else { + return $val; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return wincache_ucache_delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return wincache_ucache_clear(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $memInfo = wincache_ucache_meminfo(); + $info = wincache_ucache_info(); + $date = (new \DateTime())->setTimestamp(time() - $info[ 'total_cache_uptime' ]); + + return (new driverStatistic()) + ->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822))) + ->setSize($memInfo[ 'memory_free' ] - $memInfo[ 'memory_total' ]) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData($memInfo); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Item.php new file mode 100644 index 0000000..eb51d62 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Wincache/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Wincache; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Wincache\Driver as WincacheDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Wincache + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Wincache\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(WincacheDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof WincacheDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Driver.php new file mode 100644 index 0000000..fc0d134 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Driver.php @@ -0,0 +1,148 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Xcache; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + return extension_loaded('xcache') && function_exists('xcache_get'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return xcache_set($item->getKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl()); + + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $data = $this->decode(xcache_get($item->getKey())); + if ($data === false || $data === '') { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return xcache_unset($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + $cnt = xcache_count(XC_TYPE_VAR); + for ($i = 0; $i < $cnt; $i++) { + xcache_clear_cache(XC_TYPE_VAR, $i); + } + + return true; + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + if (!ini_get('xcache.admin.enable_auth')) { + $info = xcache_info(XC_TYPE_VAR, 0); + + return (new driverStatistic()) + ->setSize(abs($info[ 'size' ] - $info[ 'avail' ])) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("Xcache v%s with following modules loaded:\n %s", XCACHE_VERSION, str_replace(' ', ', ', XCACHE_MODULES))) + ->setRawData($info); + } else { + throw new \RuntimeException("PhpFastCache is not able to read Xcache configuration. Please put this to your php.ini:\n + [xcache.admin] + xcache.admin.enable_auth = Off\n + Then reboot your webserver and make sure that the native Xcache ini configuration file does not override your setting."); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Item.php new file mode 100644 index 0000000..7749fb8 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Xcache/Item.php @@ -0,0 +1,63 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +namespace phpFastCache\Drivers\Xcache; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Xcache\Driver as XcacheDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Xcache\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(XcacheDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof XcacheDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Driver.php new file mode 100644 index 0000000..69b8210 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Driver.php @@ -0,0 +1,141 @@ + + * + */ + +namespace phpFastCache\Drivers\Zenddisk; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver (zend disk cache) + * Requires Zend Data Cache Functions from ZendServer + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store')) { + return true; + } else { + return false; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $data = zend_disk_cache_fetch($item->getKey()); + if ($data === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return zend_disk_cache_delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return @zend_disk_cache_clear(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + $stat = new driverStatistic(); + $stat->setInfo('[ZendDisk] A void info string') + ->setSize(0) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setRawData(false); + + return $stat; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Item.php new file mode 100644 index 0000000..74efb59 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Zenddisk/Item.php @@ -0,0 +1,62 @@ + + * + */ + +namespace phpFastCache\Drivers\Zenddisk; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Zenddisk\Driver as ZendDiskDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Zenddisk + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Zenddisk\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(ZendDiskDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ZendDiskDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Driver.php b/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Driver.php new file mode 100644 index 0000000..1b1b2f3 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Driver.php @@ -0,0 +1,149 @@ + + * + */ + +namespace phpFastCache\Drivers\Zendshm; + +use phpFastCache\Core\DriverAbstract; +use phpFastCache\Core\StandardPsr6StructureTrait; +use phpFastCache\Entities\driverStatistic; +use phpFastCache\Exceptions\phpFastCacheDriverCheckException; +use phpFastCache\Exceptions\phpFastCacheDriverException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver (zend memory cache) + * Requires Zend Data Cache Functions from ZendServer + * @package phpFastCache\Drivers + */ +class Driver extends DriverAbstract +{ + /** + * Driver constructor. + * @param array $config + * @throws phpFastCacheDriverException + */ + public function __construct(array $config = []) + { + $this->setup($config); + + if (!$this->driverCheck()) { + throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + } + + /** + * @return bool + */ + public function driverCheck() + { + if (extension_loaded('Zend Data Cache') && function_exists('zend_shm_cache_store')) { + return true; + } else { + return false; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws \InvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - time(); + + return zend_shm_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + protected function driverRead(CacheItemInterface $item) + { + $data = zend_shm_cache_fetch($item->getKey()); + if ($data === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws \InvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return zend_shm_cache_delete($item->getKey()); + } else { + throw new \InvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear() + { + return @zend_shm_cache_clear(); + } + + /** + * @return bool + */ + protected function driverConnect() + { + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return driverStatistic + */ + public function getStats() + { + if(function_exists('zend_shm_cache_info')) { + $stats = (array)zend_shm_cache_info(); + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo(sprintf("The Zend memory have %d item(s) in cache.\n For more information see RawData.", $stats['items_total'])) + ->setRawData($stats) + ->setSize($stats['memory_total']); + } else { + /** zend_shm_cache_info supported V8 or higher */ + return (new driverStatistic()) + ->setData(implode(', ', array_keys($this->itemInstances))) + ->setInfo("The Zend memory statistics is only supported by ZendServer V8 or higher") + ->setRawData(null) + ->setSize(0); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Item.php b/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Item.php new file mode 100644 index 0000000..44c3118 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Drivers/Zendshm/Item.php @@ -0,0 +1,62 @@ + + * + */ + +namespace phpFastCache\Drivers\Zendshm; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\Cache\ExtendedCacheItemPoolInterface; +use phpFastCache\Cache\ItemBaseTrait; +use phpFastCache\Drivers\Zendshm\Driver as ZendSHMDriver; + +/** + * Class Item + * @package phpFastCache\Drivers\Zendshm + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait; + + /** + * Item constructor. + * @param \phpFastCache\Drivers\Zendshm\Driver $driver + * @param $key + * @throws \InvalidArgumentException + */ + public function __construct(ZendSHMDriver $driver, $key) + { + if (is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + } else { + throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); + } + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws \InvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ZendSHMDriver) { + $this->driver = $driver; + + return $this; + } else { + throw new \InvalidArgumentException('Invalid driver instance'); + } + } +} \ No newline at end of file diff --git a/lib/phpfastcache/src/phpFastCache/Entities/driverStatistic.php b/lib/phpfastcache/src/phpFastCache/Entities/driverStatistic.php new file mode 100644 index 0000000..c08afac --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Entities/driverStatistic.php @@ -0,0 +1,227 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +namespace phpFastCache\Entities; + +use ArrayAccess; +use InvalidArgumentException; +use LogicException; + +/** + * Class driverStatistic + * @package phpFastCache\Entities + */ +class driverStatistic implements ArrayAccess +{ + /** + * @var string + */ + protected $info = ''; + + /** + * @var string + */ + protected $size = 0; + + /** + * @var string + */ + protected $data = ''; + + /** + * @var mixed + */ + protected $rawData; + + /** + * @return string|bool Return infos or false if no information available + */ + public function getInfo() + { + return $this->info; + } + + /** + * @return int|bool Return size in octet or false if no information available + */ + public function getSize() + { + return $this->size; + } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } + + /** + * @param $info + * @return $this + */ + public function setInfo($info) + { + $this->info = ($info ?: ''); + + return $this; + } + + + /** + * @param int $size + * @return $this + */ + public function setSize($size) + { + $this->size = ($size ?: 0); + + return $this; + } + + /** + * @param mixed $data + * @return $this + */ + public function setData($data) + { + $this->data = ($data ?: ''); + + return $this; + } + + /** + * @return mixed + */ + public function getRawData() + { + return $this->rawData; + } + + /** + * @param mixed $raw + * @return $this + */ + public function setRawData($raw) + { + $this->rawData = $raw; + + return $this; + } + + /** + * @return array + */ + public function getPublicDesc() + { + return[ + 'Info' => 'Cache Information', + 'Size' => 'Cache Size', + 'Data' => 'Cache items keys', + 'RawData' => 'Cache raw data', + ]; + } + + /***************** + * ArrayAccess + *****************/ + + /** + * @param string $offset + * @param string $value + * @throws InvalidArgumentException + * @throws LogicException + */ + public function offsetSet($offset, $value) + { + trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); + if (!is_string($offset)) { + throw new InvalidArgumentException('$offset must be a string'); + } else { + if (property_exists($this, $offset)) { + $this->{$offset} = $value; + } else { + throw new LogicException("Property {$offset} does not exists"); + } + } + } + + /** + * @param string $offset + * @return bool + * @throws InvalidArgumentException + * @throws LogicException + */ + public function offsetExists($offset) + { + trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); + if (!is_string($offset)) { + throw new InvalidArgumentException('$offset must be a string'); + } else { + if (property_exists($this, $offset)) { + return isset($this->{$offset}); + } else { + throw new LogicException("Property {$offset} does not exists"); + } + } + } + + /** + * @param string $offset + * @throws InvalidArgumentException + * @throws LogicException + */ + public function offsetUnset($offset) + { + trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); + if (!is_string($offset)) { + throw new InvalidArgumentException('$offset must be a string'); + } else { + if (property_exists($this, $offset)) { + unset($this->{$offset}); + } else { + throw new LogicException("Property {$offset} does not exists"); + } + } + } + + /** + * @param string $offset + * @return string + * @throws InvalidArgumentException + * @throws LogicException + */ + public function offsetGet($offset) + { + trigger_error($this->getDeprecatedMsg(), E_USER_DEPRECATED); + if (!is_string($offset)) { + throw new InvalidArgumentException('$offset must be a string'); + } else { + if (property_exists($this, $offset)) { + return isset($this->{$offset}) ? $this->{$offset} : null; + } else { + throw new LogicException("Property {$offset} does not exists"); + } + } + } + + /** + * @return string + */ + private function getDeprecatedMsg() + { + return 'You should consider upgrading your code and treat the statistic array as an object. + The arrayAccess compatibility will be removed in the next major release'; + } +} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Exceptions/phpFastCacheCoreException.php b/lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheCoreException.php similarity index 100% rename from lib/phpfastcache/phpFastCache/Exceptions/phpFastCacheCoreException.php rename to lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheCoreException.php diff --git a/lib/phpfastcache/autoload.php b/lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheDriverCheckException.php similarity index 61% rename from lib/phpfastcache/autoload.php rename to lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheDriverCheckException.php index b21baf8..d66306f 100644 --- a/lib/phpfastcache/autoload.php +++ b/lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheDriverCheckException.php @@ -12,4 +12,13 @@ * */ -require_once __DIR__."/phpFastCache/phpFastCache.php"; \ No newline at end of file +namespace phpFastCache\Exceptions; + +/** + * Class phpFastCacheDriverCheckException + * @package phpFastCache\Exceptions + */ +class phpFastCacheDriverCheckException extends phpFastCacheDriverException +{ + +} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Exceptions/phpFastCacheDriverException.php b/lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheDriverException.php similarity index 100% rename from lib/phpfastcache/phpFastCache/Exceptions/phpFastCacheDriverException.php rename to lib/phpfastcache/src/phpFastCache/Exceptions/phpFastCacheDriverException.php diff --git a/lib/phpfastcache/src/phpFastCache/Proxy/phpFastCacheAbstractProxy.php b/lib/phpfastcache/src/phpFastCache/Proxy/phpFastCacheAbstractProxy.php new file mode 100644 index 0000000..77b0823 --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Proxy/phpFastCacheAbstractProxy.php @@ -0,0 +1,83 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +namespace phpFastCache\Proxy; + +use phpFastCache\Cache\ExtendedCacheItemInterface; +use phpFastCache\CacheManager; +use phpFastCache\Entities\driverStatistic; +use Psr\Cache\CacheItemInterface; + +/** + * Class phpFastCache + * + * Handle methods using annotations for IDE + * because they're handled by __call() + * Check out ExtendedCacheItemInterface to see all + * the drivers methods magically implemented + * + * @method ExtendedCacheItemInterface getItem($key) Retrieve an item and returns an empty item if not found + * @method ExtendedCacheItemInterface[] getItems(array $keys) Retrieve an item and returns an empty item if not found + * @method bool hasItem() hasItem($key) Tests if an item exists + * @method bool deleteItem(string $key) Delete an item + * @method bool deleteItems(array $keys) Delete some items + * @method bool save(CacheItemInterface $item) Save an item + * @method bool saveDeferred(CacheItemInterface $item) Sets a cache item to be persisted later + * @method bool commit() Persists any deferred cache items + * @method bool clear() Allow you to completely empty the cache and restart from the beginning + * @method driverStatistic stats() Returns a driverStatistic object + * @method ExtendedCacheItemInterface getItemsByTag($tagName) Return items by a tag + * @method ExtendedCacheItemInterface[] getItemsByTags(array $tagNames) Return items by some tags + * @method bool deleteItemsByTag($tagName) Delete items by a tag + * @method bool deleteItemsByTags(array $tagNames) // Delete items by some tags + * @method void incrementItemsByTag($tagName, $step = 1) // Increment items by a tag + * @method void incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags + * @method void decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag + * @method void decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags + * @method void appendItemsByTag($tagName, $data) // Append items by a tag + * @method void appendItemsByTags(array $tagNames, $data) // Append items by a tags + * @method void prependItemsByTag($tagName, $data) // Prepend items by a tag + * @method void prependItemsByTags(array $tagNames, $data) // Prepend items by a tags + */ +abstract class phpFastCacheAbstractProxy +{ + /** + * @var \phpFastCache\Cache\ExtendedCacheItemPoolInterface + */ + protected $instance; + + /** + * phpFastCache constructor. + * @param string $driver + * @param array $config + */ + public function __construct($driver = 'auto', array $config = []) + { + $this->instance = CacheManager::getInstance($driver, $config); + } + + /** + * @param $name + * @param $args + * @return mixed + * @throws \BadMethodCallException + */ + public function __call($name, $args) + { + if(method_exists($this->instance, $name)){ + return call_user_func_array([$this->instance, $name], $args); + }else{ + throw new \BadMethodCallException(sprintf('Method %s does not exists', $name)); + } + } +} diff --git a/lib/phpfastcache/src/phpFastCache/Util/Directory.php b/lib/phpfastcache/src/phpFastCache/Util/Directory.php new file mode 100644 index 0000000..fe30c1d --- /dev/null +++ b/lib/phpfastcache/src/phpFastCache/Util/Directory.php @@ -0,0 +1,143 @@ + http://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +namespace phpFastCache\Util; + +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use SplFileInfo; + +/** + * Class Directory + * @package phpFastCache\Util + */ +class Directory +{ + /** + * Get the directory size + * @param string $directory + * @param bool $includeDirAllocSize + * @return integer + */ + public static function dirSize($directory, $includeDirAllocSize = false) + { + $size = 0; + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { + /** + * @var \SplFileInfo $file + */ + if ($file->isFile()) { + $size += filesize($file->getRealPath()); + } else if ($includeDirAllocSize) { + $size += $file->getSize(); + } + } + + return $size; + } + + /** + * @param string $path + * @return int + */ + public static function getFileCount($path) + { + $count = 0; + $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST); + foreach ($objects as $object) { + /** + * @var \SplFileInfo $object + */ + if ($object->isFile()) { + $count++; + } + } + + return $count; + } + + /** + * Recursively delete a directory and all of it's contents - e.g.the equivalent of `rm -r` on the command-line. + * Consistent with `rmdir()` and `unlink()`, an E_WARNING level error will be generated on failure. + * + * @param string $source absolute path to directory or file to delete. + * @param bool $removeOnlyChildren set to true will only remove content inside directory. + * + * @return bool true on success; false on failure + */ + public static function rrmdir($source, $removeOnlyChildren = false) + { + if (empty($source) || file_exists($source) === false) { + return false; + } + + if (is_file($source) || is_link($source)) { + return unlink($source); + } + + $files = new RecursiveIteratorIterator + ( + new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + + foreach ($files as $fileinfo) { + /** + * @var SplFileInfo $fileinfo + */ + if ($fileinfo->isDir()) { + if (self::rrmdir($fileinfo->getRealPath()) === false) { + return false; + } + } else if(unlink($fileinfo->getRealPath()) === false) { + return false; + } + } + + if ($removeOnlyChildren === false) { + return rmdir($source); + } + + return true; + } + + /** + * Alias of realpath() but work + * on non-existing files + * + * @param $path + * @return string + */ + public static function getAbsolutePath($path) + { + $parts = preg_split('~[/\\\\]+~', $path, 0, PREG_SPLIT_NO_EMPTY); + $absolutes = []; + foreach ($parts as $part) { + if ('.' === $part) { + continue; + } + if ('..' === $part) { + array_pop($absolutes); + } else { + $absolutes[] = $part; + } + } + + /** + * Allows to dereference char + */ + $__FILE__ = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. + $prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; + return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes); + } +} \ No newline at end of file diff --git a/lib/phpfastcache/phpFastCache/Util/Languages.php b/lib/phpfastcache/src/phpFastCache/Util/Languages.php similarity index 84% rename from lib/phpfastcache/phpFastCache/Util/Languages.php rename to lib/phpfastcache/src/phpFastCache/Util/Languages.php index 484c590..071d62d 100644 --- a/lib/phpfastcache/phpFastCache/Util/Languages.php +++ b/lib/phpfastcache/src/phpFastCache/Util/Languages.php @@ -13,6 +13,7 @@ */ namespace phpFastCache\Util; + use phpFastCache\Exceptions\phpFastCacheCoreException; @@ -26,13 +27,12 @@ class Languages { public static function setEncoding($encoding = 'UTF-8', $language = null) { - if ($language === null || !in_array($language, array('uni', 'Japanese', 'ja', 'English', 'en'), true)) { + if ($language === null || !in_array($language, ['uni', 'Japanese', 'ja', 'English', 'en'], true)) { $language = 'uni'; } - switch(strtoupper($encoding)) - { + switch (strtoupper($encoding)) { case 'UTF-8': - if(extension_loaded("mbstring")) { + if (extension_loaded("mbstring")) { mb_internal_encoding($encoding); mb_http_output($encoding); mb_http_input($encoding); diff --git a/lib/phpfastcache/phpFastCache/index.html b/lib/phpfastcache/src/phpFastCache/index.html similarity index 100% rename from lib/phpfastcache/phpFastCache/index.html rename to lib/phpfastcache/src/phpFastCache/index.html diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Helper/String.php b/lib/ts3phpframework/libraries/TeamSpeak3/Helper/String.php index 08e7483..a1d20bb 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Helper/String.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Helper/String.php @@ -393,7 +393,7 @@ class TeamSpeak3_Helper_String implements ArrayAccess, Iterator, Countable */ public function isInt() { - return (is_numeric($this->string) && !$this->contains(".")) ? TRUE : FALSE; + return (is_numeric($this->string) && !$this->contains(".") && !$this->contains("x")) ? TRUE : FALSE; } /** diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channel.php b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channel.php index cbc1835..1242ef0 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channel.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channel.php @@ -446,8 +446,6 @@ class TeamSpeak3_Node_Channel extends TeamSpeak3_Node_Abstract public function delete($force = FALSE) { $this->getParent()->channelDelete($this->getId(), $force); - - unset($this); } /** diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channelgroup.php b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channelgroup.php index dadc70f..7e40e4a 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channelgroup.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Channelgroup.php @@ -74,8 +74,6 @@ class TeamSpeak3_Node_Channelgroup extends TeamSpeak3_Node_Abstract public function delete($force = FALSE) { $this->getParent()->channelGroupDelete($this->getId(), $force); - - unset($this); } /** diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Client.php b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Client.php index 0744267..53feaf5 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Client.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Client.php @@ -285,7 +285,7 @@ class TeamSpeak3_Node_Client extends TeamSpeak3_Node_Abstract */ public function avatarDownload() { - if($this["client_flag_avatar"] == 0) return; + if($this["client_flag_avatar"] == NULL) return; $download = $this->getParent()->transferInitDownload(rand(0x0000, 0xFFFF), 0, $this->avatarGetName()); $transfer = TeamSpeak3::factory("filetransfer://" . (strstr($download["host"], ":") !== FALSE ? "[" . $download["host"] . "]" : $download["host"]) . ":" . $download["port"]); diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Server.php b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Server.php index 0d15926..5854554 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Server.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Server.php @@ -501,7 +501,9 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract */ public function channelFileInfo($cid, $cpw = "", $name = "/") { - return array_pop($this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray()); + $info = $this->execute("ftgetfileinfo", array("cid" => $cid, "cpw" => $cpw, "name" => $name))->toArray(); + + return array_pop($info); } /** @@ -2268,8 +2270,6 @@ class TeamSpeak3_Node_Server extends TeamSpeak3_Node_Abstract public function delete() { $this->getParent()->serverDelete($this->getId()); - - unset($this); } /** diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Servergroup.php b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Servergroup.php index d836b34..28eb5d1 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Node/Servergroup.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Node/Servergroup.php @@ -74,8 +74,6 @@ class TeamSpeak3_Node_Servergroup extends TeamSpeak3_Node_Abstract public function delete($force = FALSE) { $this->getParent()->serverGroupDelete($this->getId(), $force); - - unset($this); } /** diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Transport/Abstract.php b/lib/ts3phpframework/libraries/TeamSpeak3/Transport/Abstract.php index 5350aa5..3e4e310 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Transport/Abstract.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Transport/Abstract.php @@ -186,7 +186,7 @@ abstract class TeamSpeak3_Transport_Abstract */ public function setAdapter(TeamSpeak3_Adapter_Abstract $adapter) { - $this->adapter = $adapter; + $this->adapter = get_class($adapter); } /** @@ -208,7 +208,7 @@ abstract class TeamSpeak3_Transport_Abstract { if($this->adapter instanceof TeamSpeak3_Adapter_Abstract) { - $string = TeamSpeak3_Helper_String::factory(get_class($this->adapter)); + $string = TeamSpeak3_Helper_String::factory($this->adapter); return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString(); } diff --git a/lib/ts3phpframework/libraries/TeamSpeak3/Viewer/Html.php b/lib/ts3phpframework/libraries/TeamSpeak3/Viewer/Html.php index 5901457..5fdf9cc 100644 --- a/lib/ts3phpframework/libraries/TeamSpeak3/Viewer/Html.php +++ b/lib/ts3phpframework/libraries/TeamSpeak3/Viewer/Html.php @@ -168,7 +168,7 @@ class TeamSpeak3_Viewer_Html implements TeamSpeak3_Viewer_Interface { return "ts3_viewer " . $this->currObj->getClass(null); } - + /** * Returns the ID of the current node which will be used as a summary element for * the container element. diff --git a/viewer.php b/viewer.php index a0e398f..3bd90df 100644 --- a/viewer.php +++ b/viewer.php @@ -1,24 +1,16 @@ get('tsviewer'); - -// $cache->clean(); - -if (is_null($tsviewer)) { - $tsviewer = array(getViewer(), date('d-m-Y H:i:s')); - $cache->set('tsviewer', $tsviewer, 300); +if($cacheutils->isExpired()) { + $cacheutils->setValue([getViewer(), date('d-m-Y H:i:s')], 300); } +$tsviewer = $cacheutils->getValue(); + // print_r ($tsviewer); function getViewer() {