2
0

Capture.php 2.0 KB

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