File indexing completed on 2025-01-19 05:20:57
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Cache 0017 * @subpackage Zend_Cache_Frontend 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 0024 /** 0025 * @see Zend_Cache_Core 0026 */ 0027 // require_once 'Zend/Cache/Core.php'; 0028 0029 0030 /** 0031 * @package Zend_Cache 0032 * @subpackage Zend_Cache_Frontend 0033 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0034 * @license http://framework.zend.com/license/new-bsd New BSD License 0035 */ 0036 class Zend_Cache_Frontend_Output extends Zend_Cache_Core 0037 { 0038 0039 private $_idStack = array(); 0040 0041 /** 0042 * Constructor 0043 * 0044 * @param array $options Associative array of options 0045 * @return void 0046 */ 0047 public function __construct(array $options = array()) 0048 { 0049 parent::__construct($options); 0050 $this->_idStack = array(); 0051 } 0052 0053 /** 0054 * Start the cache 0055 * 0056 * @param string $id Cache id 0057 * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested 0058 * @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simply returned else) 0059 * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas) 0060 */ 0061 public function start($id, $doNotTestCacheValidity = false, $echoData = true) 0062 { 0063 $data = $this->load($id, $doNotTestCacheValidity); 0064 if ($data !== false) { 0065 if ( $echoData ) { 0066 echo($data); 0067 return true; 0068 } else { 0069 return $data; 0070 } 0071 } 0072 ob_start(); 0073 ob_implicit_flush(false); 0074 $this->_idStack[] = $id; 0075 return false; 0076 } 0077 0078 /** 0079 * Stop the cache 0080 * 0081 * @param array $tags Tags array 0082 * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) 0083 * @param string $forcedDatas If not null, force written datas with this 0084 * @param boolean $echoData If set to true, datas are sent to the browser 0085 * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends 0086 * @return void 0087 */ 0088 public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8) 0089 { 0090 if ($forcedDatas === null) { 0091 $data = ob_get_clean(); 0092 } else { 0093 $data =& $forcedDatas; 0094 } 0095 $id = array_pop($this->_idStack); 0096 if ($id === null) { 0097 Zend_Cache::throwException('use of end() without a start()'); 0098 } 0099 $this->save($data, $id, $tags, $specificLifetime, $priority); 0100 if ($echoData) { 0101 echo($data); 0102 } 0103 } 0104 0105 }