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

/library/Zend/Cache/Frontend/Output.php

https://bitbucket.org/ksekar/campus
PHP | 105 lines | 43 code | 9 blank | 53 comment | 7 complexity | 513cf8649f73b76a683c75dc91a28d23 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: Output.php 24801 2012-05-13 12:03:22Z mabe $
  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_Output extends Zend_Cache_Core
  33. {
  34. private $_idStack = array();
  35. /**
  36. * Constructor
  37. *
  38. * @param array $options Associative array of options
  39. * @return void
  40. */
  41. public function __construct(array $options = array())
  42. {
  43. parent::__construct($options);
  44. $this->_idStack = array();
  45. }
  46. /**
  47. * Start the cache
  48. *
  49. * @param string $id Cache id
  50. * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
  51. * @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simply returned else)
  52. * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
  53. */
  54. public function start($id, $doNotTestCacheValidity = false, $echoData = true)
  55. {
  56. $data = $this->load($id, $doNotTestCacheValidity);
  57. if ($data !== false) {
  58. if ( $echoData ) {
  59. echo($data);
  60. return true;
  61. } else {
  62. return $data;
  63. }
  64. }
  65. ob_start();
  66. ob_implicit_flush(false);
  67. $this->_idStack[] = $id;
  68. return false;
  69. }
  70. /**
  71. * Stop the cache
  72. *
  73. * @param array $tags Tags array
  74. * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
  75. * @param string $forcedDatas If not null, force written datas with this
  76. * @param boolean $echoData If set to true, datas are sent to the browser
  77. * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
  78. * @return void
  79. */
  80. public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
  81. {
  82. if ($forcedDatas === null) {
  83. $data = ob_get_clean();
  84. } else {
  85. $data =& $forcedDatas;
  86. }
  87. $id = array_pop($this->_idStack);
  88. if ($id === null) {
  89. Zend_Cache::throwException('use of end() without a start()');
  90. }
  91. $this->save($data, $id, $tags, $specificLifetime, $priority);
  92. if ($echoData) {
  93. echo($data);
  94. }
  95. }
  96. }