Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
output.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Cache
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Joomla Cache output type object
14  *
15  * @package Joomla.Platform
16  * @subpackage Cache
17  * @since 11.1
18  */
20 {
21  /**
22  * Cache data ID
23  *
24  * @var string
25  * @since 11.1
26  */
27  protected $_id;
28 
29  /**
30  * Cache data group
31  *
32  * @var string
33  * @since 11.1
34  */
35  protected $_group;
36 
37  /**
38  * Object to test locked state
39  *
40  * @var object
41  * @since 11.1
42  */
43  protected $_locktest = null;
44 
45  /**
46  * Start the cache
47  *
48  * @param string $id The cache data id
49  * @param string $group The cache data group
50  *
51  * @return boolean True if the cache is hit (false else)
52  *
53  * @since 11.1
54  */
55  public function start($id, $group = null)
56  {
57  // If we have data in cache use that.
58  $data = $this->cache->get($id, $group);
59 
60  $this->_locktest = new stdClass;
61  $this->_locktest->locked = null;
62  $this->_locktest->locklooped = null;
63 
64  if ($data === false)
65  {
66  $this->_locktest = $this->cache->lock($id, $group);
67  if ($this->_locktest->locked == true && $this->_locktest->locklooped == true)
68  {
69  $data = $this->cache->get($id, $group);
70  }
71  }
72 
73  if ($data !== false)
74  {
75  $data = unserialize(trim($data));
76  echo $data;
77  if ($this->_locktest->locked == true)
78  {
79  $this->cache->unlock($id, $group);
80  }
81  return true;
82  }
83  else
84  {
85  // Nothing in cache... let's start the output buffer and start collecting data for next time.
86  if ($this->_locktest->locked == false)
87  {
88  $this->_locktest = $this->cache->lock($id, $group);
89  }
90  ob_start();
91  ob_implicit_flush(false);
92 
93  // Set id and group placeholders
94  $this->_id = $id;
95  $this->_group = $group;
96 
97  return false;
98  }
99  }
100 
101  /**
102  * Stop the cache buffer and store the cached data
103  *
104  * @return boolean True if cache stored
105  *
106  * @since 11.1
107  */
108  public function end()
109  {
110  // Get data from output buffer and echo it
111  $data = ob_get_contents();
112  ob_end_clean();
113  echo $data;
114 
115  // Get id and group and reset them placeholders
116  $id = $this->_id;
117  $group = $this->_group;
118  $this->_id = null;
119  $this->_group = null;
120 
121  // Get the storage handler and store the cached data
122  $ret = $this->cache->store(serialize($data), $id, $group);
123 
124  if ($this->_locktest->locked == true)
125  {
126  $this->cache->unlock($id, $group);
127  }
128 
129  return $ret;
130  }
131 }