Source for file output.php

Documentation is available at output.php

  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.  */
  19. {
  20.     /**
  21.      * Cache data ID
  22.      *
  23.      * @var    string 
  24.      * @since  11.1
  25.      */
  26.     protected $_id;
  27.  
  28.     /**
  29.      * Cache data group
  30.      *
  31.      * @var    string 
  32.      * @since  11.1
  33.      */
  34.     protected $_group;
  35.  
  36.     /**
  37.      * Object to test locked state
  38.      *
  39.      * @var    object 
  40.      * @since  11.1
  41.      */
  42.     protected $_locktest = null;
  43.  
  44.     /**
  45.      * Start the cache
  46.      *
  47.      * @param   string  $id     The cache data id
  48.      * @param   string  $group  The cache data group
  49.      *
  50.      * @return  boolean  True if the cache is hit (false else)
  51.      *
  52.      * @since   11.1
  53.      */
  54.     public function start($id$group null)
  55.     {
  56.         // If we have data in cache use that.
  57.         $data $this->cache->get($id$group);
  58.  
  59.         $this->_locktest = new stdClass;
  60.         $this->_locktest->locked null;
  61.         $this->_locktest->locklooped null;
  62.  
  63.         if ($data === false)
  64.         {
  65.             $this->_locktest = $this->cache->lock($id$group);
  66.             if ($this->_locktest->locked == true && $this->_locktest->locklooped == true)
  67.             {
  68.                 $data $this->cache->get($id$group);
  69.             }
  70.         }
  71.  
  72.         if ($data !== false)
  73.         {
  74.             $data unserialize(trim($data));
  75.             echo $data;
  76.             if ($this->_locktest->locked == true)
  77.             {
  78.                 $this->cache->unlock($id$group);
  79.             }
  80.             return true;
  81.         }
  82.         else
  83.         {
  84.             // Nothing in cache... let's start the output buffer and start collecting data for next time.
  85.             if ($this->_locktest->locked == false)
  86.             {
  87.                 $this->_locktest = $this->cache->lock($id$group);
  88.             }
  89.             ob_start();
  90.             ob_implicit_flush(false);
  91.  
  92.             // Set id and group placeholders
  93.             $this->_id = $id;
  94.             $this->_group = $group;
  95.  
  96.             return false;
  97.         }
  98.     }
  99.  
  100.     /**
  101.      * Stop the cache buffer and store the cached data
  102.      *
  103.      * @return  boolean  True if cache stored
  104.      *
  105.      * @since   11.1
  106.      */
  107.     public function end()
  108.     {
  109.         // Get data from output buffer and echo it
  110.         $data ob_get_contents();
  111.         ob_end_clean();
  112.         echo $data;
  113.  
  114.         // Get id and group and reset them placeholders
  115.         $id $this->_id;
  116.         $group $this->_group;
  117.         $this->_id = null;
  118.         $this->_group = null;
  119.  
  120.         // Get the storage handler and store the cached data
  121.         $ret $this->cache->store(serialize($data)$id$group);
  122.  
  123.         if ($this->_locktest->locked == true)
  124.         {
  125.             $this->cache->unlock($id$group);
  126.         }
  127.  
  128.         return $ret;
  129.     }
  130. }

Documentation generated on Tue, 19 Nov 2013 15:09:54 +0100 by phpDocumentor 1.4.3