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