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_Capture extends Zend_Cache_Core
0037 {
0038     /**
0039      * Page identifiers
0040      * @var array
0041      */
0042     protected $_idStack = array();
0043 
0044     /**
0045      * Tags
0046      * @var array
0047      */
0048     protected $_tags = array();
0049 
0050     protected $_extension = null;
0051 
0052     /**
0053      * Start the cache
0054      *
0055      * @param  string  $id Cache id
0056      * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
0057      */
0058     public function start($id, array $tags, $extension = null)
0059     {
0060         $this->_tags = $tags;
0061         $this->_extension = $extension;
0062         ob_start(array($this, '_flush'));
0063         ob_implicit_flush(false);
0064         $this->_idStack[] = $id;
0065         return false;
0066     }
0067 
0068     /**
0069      * callback for output buffering
0070      * (shouldn't really be called manually)
0071      *
0072      * @param  string $data Buffered output
0073      * @return string Data to send to browser
0074      */
0075     public function _flush($data)
0076     {
0077         $id = array_pop($this->_idStack);
0078         if ($id === null) {
0079             Zend_Cache::throwException('use of _flush() without a start()');
0080         }
0081         if ($this->_extension) {
0082             $this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
0083         } else {
0084             $this->save($data, $id, $this->_tags);
0085         }
0086         return $data;
0087     }
0088 }