|
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: Output.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
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_Output extends Zend_Cache_Core |
|
37 { |
|
38 |
|
39 private $_idStack = array(); |
|
40 |
|
41 /** |
|
42 * Constructor |
|
43 * |
|
44 * @param array $options Associative array of options |
|
45 * @return void |
|
46 */ |
|
47 public function __construct(array $options = array()) |
|
48 { |
|
49 parent::__construct($options); |
|
50 $this->_idStack = array(); |
|
51 } |
|
52 |
|
53 /** |
|
54 * Start the cache |
|
55 * |
|
56 * @param string $id Cache id |
|
57 * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested |
|
58 * @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simpy returned else) |
|
59 * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas) |
|
60 */ |
|
61 public function start($id, $doNotTestCacheValidity = false, $echoData = true) |
|
62 { |
|
63 $data = $this->load($id, $doNotTestCacheValidity); |
|
64 if ($data !== false) { |
|
65 if ( $echoData ) { |
|
66 echo($data); |
|
67 return true; |
|
68 } else { |
|
69 return $data; |
|
70 } |
|
71 } |
|
72 ob_start(); |
|
73 ob_implicit_flush(false); |
|
74 $this->_idStack[] = $id; |
|
75 return false; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Stop the cache |
|
80 * |
|
81 * @param array $tags Tags array |
|
82 * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) |
|
83 * @param string $forcedDatas If not null, force written datas with this |
|
84 * @param boolean $echoData If set to true, datas are sent to the browser |
|
85 * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends |
|
86 * @return void |
|
87 */ |
|
88 public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8) |
|
89 { |
|
90 if ($forcedDatas === null) { |
|
91 $data = ob_get_contents(); |
|
92 ob_end_clean(); |
|
93 } else { |
|
94 $data =& $forcedDatas; |
|
95 } |
|
96 $id = array_pop($this->_idStack); |
|
97 if ($id === null) { |
|
98 Zend_Cache::throwException('use of end() without a start()'); |
|
99 } |
|
100 $this->save($data, $id, $tags, $specificLifetime, $priority); |
|
101 if ($echoData) { |
|
102 echo($data); |
|
103 } |
|
104 } |
|
105 |
|
106 } |