|
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_Frontend |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Capture.php 22662 2010-07-24 17:37:36Z mabe $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * @see Zend_Cache_Core |
|
26 */ |
|
27 require_once 'Zend/Cache/Core.php'; |
|
28 |
|
29 |
|
30 /** |
|
31 * @package Zend_Cache |
|
32 * @subpackage Zend_Cache_Frontend |
|
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
35 */ |
|
36 class Zend_Cache_Frontend_Capture extends Zend_Cache_Core |
|
37 { |
|
38 /** |
|
39 * Page identifiers |
|
40 * @var array |
|
41 */ |
|
42 protected $_idStack = array(); |
|
43 |
|
44 /** |
|
45 * Tags |
|
46 * @var array |
|
47 */ |
|
48 protected $_tags = array(); |
|
49 |
|
50 protected $_extension = null; |
|
51 |
|
52 /** |
|
53 * Start the cache |
|
54 * |
|
55 * @param string $id Cache id |
|
56 * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas) |
|
57 */ |
|
58 public function start($id, array $tags, $extension = null) |
|
59 { |
|
60 $this->_tags = $tags; |
|
61 $this->_extension = $extension; |
|
62 ob_start(array($this, '_flush')); |
|
63 ob_implicit_flush(false); |
|
64 $this->_idStack[] = $id; |
|
65 return false; |
|
66 } |
|
67 |
|
68 /** |
|
69 * callback for output buffering |
|
70 * (shouldn't really be called manually) |
|
71 * |
|
72 * @param string $data Buffered output |
|
73 * @return string Data to send to browser |
|
74 */ |
|
75 public function _flush($data) |
|
76 { |
|
77 $id = array_pop($this->_idStack); |
|
78 if ($id === null) { |
|
79 Zend_Cache::throwException('use of _flush() without a start()'); |
|
80 } |
|
81 if ($this->_extension) { |
|
82 $this->save(serialize(array($data, $this->_extension)), $id, $this->_tags); |
|
83 } else { |
|
84 $this->save($data, $id, $this->_tags); |
|
85 } |
|
86 return $data; |
|
87 } |
|
88 } |