PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Cache/Frontend/Capture.php

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