/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. * @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-2010 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. protected $_extension = null;
  44. /**
  45. * Start the cache
  46. *
  47. * @param string $id Cache id
  48. * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
  49. */
  50. public function start($id, array $tags, $extension = null)
  51. {
  52. $this->_tags = $tags;
  53. $this->_extension = $extension;
  54. ob_start(array($this, '_flush'));
  55. ob_implicit_flush(false);
  56. $this->_idStack[] = $id;
  57. return false;
  58. }
  59. /**
  60. * callback for output buffering
  61. * (shouldn't really be called manually)
  62. *
  63. * @param string $data Buffered output
  64. * @return string Data to send to browser
  65. */
  66. public function _flush($data)
  67. {
  68. $id = array_pop($this->_idStack);
  69. if (is_null($id)) {
  70. Zend_Cache::throwException('use of _flush() without a start()');
  71. }
  72. if ($this->_extension) {
  73. $this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
  74. } else {
  75. $this->save($data, $id, $this->_tags);
  76. }
  77. return $data;
  78. }
  79. }