PageRenderTime 35ms CodeModel.GetById 23ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/vendor/zend/Zend/Cache/Frontend/Capture.php

http://zoop.googlecode.com/
PHP | 87 lines | 30 code | 8 blank | 49 comment | 3 complexity | b1d2c280a21eaacf93e3201bb7b0ae3a MD5 | raw file
 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 */
21
22
23/**
24 * @see Zend_Cache_Core
25 */
26require_once 'Zend/Cache/Core.php';
27
28
29/**
30 * @package    Zend_Cache
31 * @subpackage Zend_Cache_Frontend
32 * @copyright  Copyright (c) 2005-2010 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 (is_null($id)) {
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}