~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Cache/Backend/Test.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Cache
 
17
 * @subpackage Zend_Cache_Backend
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 */
 
21
 
 
22
 
 
23
/**
 
24
 * @see Zend_Cache_Backend_Interface
 
25
 */
 
26
require_once 'Zend/Cache/Backend/Interface.php';
 
27
 
 
28
/**
 
29
 * @see Zend_Cache_Backend
 
30
 */
 
31
require_once 'Zend/Cache/Backend.php';
 
32
 
 
33
/**
 
34
 * @package    Zend_Cache
 
35
 * @subpackage Zend_Cache_Backend
 
36
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
37
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
38
 */
 
39
class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
 
40
{
 
41
    /**
 
42
     * Available options
 
43
     *
 
44
     * @var array available options
 
45
     */
 
46
    protected $_options = array();
 
47
 
 
48
    /**
 
49
     * Frontend or Core directives
 
50
     *
 
51
     * @var array directives
 
52
     */
 
53
    protected $_directives = array();
 
54
 
 
55
    /**
 
56
     * Array to log actions
 
57
     *
 
58
     * @var array $_log
 
59
     */
 
60
    private $_log = array();
 
61
 
 
62
    /**
 
63
     * Current index for log array
 
64
     *
 
65
     * @var int $_index
 
66
     */
 
67
    private $_index = 0;
 
68
 
 
69
    /**
 
70
     * Constructor
 
71
     *
 
72
     * @param  array $options associative array of options
 
73
     * @return void
 
74
     */
 
75
    public function __construct($options = array())
 
76
    {
 
77
        $this->_addLog('construct', array($options));
 
78
    }
 
79
 
 
80
    /**
 
81
     * Set the frontend directives
 
82
     *
 
83
     * @param  array $directives assoc of directives
 
84
     * @return void
 
85
     */
 
86
    public function setDirectives($directives)
 
87
    {
 
88
        $this->_addLog('setDirectives', array($directives));
 
89
    }
 
90
 
 
91
    /**
 
92
     * Test if a cache is available for the given id and (if yes) return it (false else)
 
93
     *
 
94
     * For this test backend only, if $id == 'false', then the method will return false
 
95
     * if $id == 'serialized', the method will return a serialized array
 
96
     * ('foo' else)
 
97
     *
 
98
     * @param  string  $id                     Cache id
 
99
     * @param  boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
 
100
     * @return string Cached datas (or false)
 
101
     */
 
102
    public function load($id, $doNotTestCacheValidity = false)
 
103
    {
 
104
        $this->_addLog('get', array($id, $doNotTestCacheValidity));
 
105
        if ($id=='false') {
 
106
            return false;
 
107
        }
 
108
        if ($id=='serialized') {
 
109
            return serialize(array('foo'));
 
110
        }
 
111
        if ($id=='serialized2') {
 
112
            return serialize(array('headers' => array(), 'data' => 'foo'));
 
113
        }
 
114
        if (($id=='71769f39054f75894288e397df04e445') or ($id=='615d222619fb20b527168340cebd0578')) {
 
115
            return serialize(array('foo', 'bar'));
 
116
        }
 
117
        if (($id=='8a02d218a5165c467e7a5747cc6bd4b6') or ($id=='648aca1366211d17cbf48e65dc570bee')) {
 
118
            return serialize(array('foo', 'bar'));
 
119
        }
 
120
        return 'foo';
 
121
    }
 
122
 
 
123
    /**
 
124
     * Test if a cache is available or not (for the given id)
 
125
     *
 
126
     * For this test backend only, if $id == 'false', then the method will return false
 
127
     * (123456 else)
 
128
     *
 
129
     * @param  string $id Cache id
 
130
     * @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
 
131
     */
 
132
    public function test($id)
 
133
    {
 
134
        $this->_addLog('test', array($id));
 
135
        if ($id=='false') {
 
136
            return false;
 
137
        }
 
138
        if (($id=='d8523b3ee441006261eeffa5c3d3a0a7') or ($id=='3c439c922209e2cb0b54d6deffccd75a')) {
 
139
            return false;
 
140
        }
 
141
        if (($id=='40f649b94977c0a6e76902e2a0b43587') or ($id=='e83249ea22178277d5befc2c5e2e9ace')) {
 
142
            return false;
 
143
        }
 
144
        return 123456;
 
145
    }
 
146
 
 
147
    /**
 
148
     * Save some string datas into a cache record
 
149
     *
 
150
     * For this test backend only, if $id == 'false', then the method will return false
 
151
     * (true else)
 
152
     *
 
153
     * @param  string $data             Datas to cache
 
154
     * @param  string $id               Cache id
 
155
     * @param  array  $tags             Array of strings, the cache record will be tagged by each string entry
 
156
     * @param  int    $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
 
157
     * @return boolean True if no problem
 
158
     */
 
159
    public function save($data, $id, $tags = array(), $specificLifetime = false)
 
160
    {
 
161
        $this->_addLog('save', array($data, $id, $tags));
 
162
        if ($id=='false') {
 
163
            return false;
 
164
        }
 
165
        return true;
 
166
    }
 
167
 
 
168
    /**
 
169
     * Remove a cache record
 
170
     *
 
171
     * For this test backend only, if $id == 'false', then the method will return false
 
172
     * (true else)
 
173
     *
 
174
     * @param  string $id Cache id
 
175
     * @return boolean True if no problem
 
176
     */
 
177
    public function remove($id)
 
178
    {
 
179
        $this->_addLog('remove', array($id));
 
180
        if ($id=='false') {
 
181
            return false;
 
182
        }
 
183
        return true;
 
184
    }
 
185
 
 
186
    /**
 
187
     * Clean some cache records
 
188
     *
 
189
     * For this test backend only, if $mode == 'false', then the method will return false
 
190
     * (true else)
 
191
     *
 
192
     * Available modes are :
 
193
     * Zend_Cache::CLEANING_MODE_ALL (default)    => remove all cache entries ($tags is not used)
 
194
     * Zend_Cache::CLEANING_MODE_OLD              => remove too old cache entries ($tags is not used)
 
195
     * Zend_Cache::CLEANING_MODE_MATCHING_TAG     => remove cache entries matching all given tags
 
196
     *                                               ($tags can be an array of strings or a single string)
 
197
     * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
 
198
     *                                               ($tags can be an array of strings or a single string)
 
199
     *
 
200
     * @param  string $mode Clean mode
 
201
     * @param  array  $tags Array of tags
 
202
     * @return boolean True if no problem
 
203
     */
 
204
    public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
 
205
    {
 
206
        $this->_addLog('clean', array($mode, $tags));
 
207
        if ($mode=='false') {
 
208
            return false;
 
209
        }
 
210
        return true;
 
211
    }
 
212
 
 
213
    /**
 
214
     * Get the last log
 
215
     *
 
216
     * @return string The last log
 
217
     */
 
218
    public function getLastLog()
 
219
    {
 
220
        return $this->_log[$this->_index - 1];
 
221
    }
 
222
 
 
223
    /**
 
224
     * Get the log index
 
225
     *
 
226
     * @return int Log index
 
227
     */
 
228
    public function getLogIndex()
 
229
    {
 
230
        return $this->_index;
 
231
    }
 
232
 
 
233
    /**
 
234
     * Get the complete log array
 
235
     *
 
236
     * @return array Complete log array
 
237
     */
 
238
    public function getAllLogs()
 
239
    {
 
240
        return $this->_log;
 
241
    }
 
242
 
 
243
    /**
 
244
     * Return true if the automatic cleaning is available for the backend
 
245
     *
 
246
     * @return boolean
 
247
     */
 
248
    public function isAutomaticCleaningAvailable()
 
249
    {
 
250
        return true;
 
251
    }
 
252
 
 
253
    /**
 
254
     * Add an event to the log array
 
255
     *
 
256
     * @param  string $methodName MethodName
 
257
     * @param  array  $args       Arguments
 
258
     * @return void
 
259
     */
 
260
    private function _addLog($methodName, $args)
 
261
    {
 
262
        $this->_log[$this->_index] = array(
 
263
            'methodName' => $methodName,
 
264
            'args' => $args
 
265
        );
 
266
        $this->_index = $this->_index + 1;
 
267
    }
 
268
 
 
269
}