PageRenderTime 34ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://zoop.googlecode.com/
PHP | 106 lines | 44 code | 9 blank | 53 comment | 7 complexity | bc45bc515c51f362fe8566cd3a43194d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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. * @version $Id: Output.php 20096 2010-01-06 02:05:09Z bkarwin $
  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-2010 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 (simpy 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_contents();
  84. ob_end_clean();
  85. } else {
  86. $data =& $forcedDatas;
  87. }
  88. $id = array_pop($this->_idStack);
  89. if ($id === null) {
  90. Zend_Cache::throwException('use of end() without a start()');
  91. }
  92. $this->save($data, $id, $tags, $specificLifetime, $priority);
  93. if ($echoData) {
  94. echo($data);
  95. }
  96. }
  97. }