1: <?php
2: /**
3: * You may not change or alter any portion of this comment or credits
4: * of supporting developers from this source code or any supporting source code
5: * which is considered copyrighted (c) material of the original comment or credit authors.
6: * This program is distributed in the hope that it will be useful,
7: * but WITHOUT ANY WARRANTY; without even the implied warranty of
8: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9: */
10:
11: namespace Xoops\Core\Cache;
12:
13: /**
14: * Legacy BC wrapper for cache
15: *
16: * @copyright (c) 2000-2015 XOOPS Project (www.xoops.org)
17: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18: * @package Xoops\Core\Cache
19: * @subpackage Legacy
20: * @since 2.3.0
21: * @author Taiwen Jiang <phppp@users.sourceforge.net>
22: */
23: class Legacy
24: {
25: /**
26: * issue deprecated warning
27: *
28: * @param string $message message to show, or empty to use default
29: * @return void
30: */
31: private static function deprecated($message = 'Obsolete cache call.')
32: {
33: //\Xoops::getInstance()->deprecated($message);
34: $stack = debug_backtrace();
35: $frameSelf = $stack[1];
36: $frame = isset($stack[2]) ? $stack[2] : false;
37: $append = ' ' . get_called_class() . '::' . $frameSelf['function'] . '() called from ';
38: if ($frame !== false) {
39: $append .= $frame['function'] . '() in ';
40: }
41: $append .= $frameSelf['file'] . ' line '. $frameSelf['line'];
42: \Xoops::getInstance()->deprecated($message . $append);
43: }
44:
45: /**
46: * get default cache
47: *
48: * @return Access cache access object
49: */
50: private static function getCache()
51: {
52: return \Xoops::getInstance()->cache();
53: }
54:
55: /**
56: * Garbage collection
57: *
58: * @return boolean true on success
59: */
60: public static function gc()
61: {
62: self::deprecated();
63: $cache = self::getCache();
64: return $cache->garbageCollect();
65: }
66:
67: /**
68: * Write data for key into cache
69: *
70: * @param string $key Identifier for the data
71: * @param mixed $value Data to be cached - anything except a resource
72: * @param mixed $duration time to live in seconds
73: *
74: * @return boolean True if the data was successfully cached, false on failure
75: */
76: public static function write($key, $value, $duration = 0)
77: {
78: self::deprecated();
79: $ttl = (int)($duration);
80: $ttl = $ttl > 0 ? $ttl : null;
81: $cache = self::getCache();
82: return $cache->write($key, $value, $ttl);
83:
84: //$key = substr(md5(\XoopsBaseConfig::get('url')), 0, 8) . '_' . $key;
85: }
86:
87: /**
88: * Read a key from the cache
89: *
90: * @param string $key Identifier for the data
91: *
92: * @return mixed The cached data, or false if the data has expired or cannot be read
93: */
94: public static function read($key)
95: {
96: self::deprecated();
97: $cache = self::getCache();
98: return $cache->read($key);
99: }
100:
101: /**
102: * Delete a key from the cache
103: *
104: * @param string $key Identifier for the data
105: *
106: * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
107: */
108: public static function delete($key)
109: {
110: self::deprecated();
111: $cache = self::getCache();
112: return $cache->delete($key);
113: }
114:
115: /**
116: * Delete all keys from the cache
117: *
118: * @return boolean True if the cache was successfully cleared, false otherwise
119: */
120: public static function clear()
121: {
122: self::deprecated();
123: $cache = self::getCache();
124: return $cache->clear();
125: }
126:
127: /**
128: * catch all deprecated message
129: *
130: * @param string $name ignored
131: * @param array $args ignored
132: *
133: * @return false
134: */
135: public function __call($name, $args)
136: {
137: self::deprecated(sprintf('XoopsCache->%s() is no longer used', $name));
138: return false;
139: }
140:
141: /**
142: * catch all deprecated message for static methods
143: *
144: * @param string $name ignored
145: * @param array $args ignored
146: *
147: * @return false
148: */
149: public static function __callStatic($name, $args)
150: {
151: self::deprecated(sprintf('XoopsCache::%s() is no longer used', $name));
152: return false;
153: }
154: }
155: