[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/domit/ -> xml_domit_cache.php (source)

   1  <?php
   2  /**
   3  * @package domit-xmlparser
   4  * @copyright (C) 2004 John Heinstein. All rights reserved
   5  * @license http://www.gnu.org/copyleft/lesser.html LGPL License
   6  * @author John Heinstein <johnkarl@nbnet.nb.ca>
   7  * @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
   8  * DOMIT! is Free Software
   9  **/
  10  
  11  /** Extension for cache files */
  12  define ('DOMIT_FILE_EXTENSION_CACHE', 'dch');
  13  
  14  /**
  15  * A simple caching mechanism for a DOMIT_Document
  16  */
  17  class DOMIT_cache {
  18      /**
  19      * Serializes and caches the specified DOMIT! document
  20      * @param string The name of the xml file to be saved
  21      * @param Object A reference to the document to be saved
  22      * @param string The write attributes for the saved document ('w' or 'wb')
  23      */
  24  	function toCache($xmlFileName, &$doc, $writeAttributes = 'w') {
  25          require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
  26          require_once (DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
  27  
  28          $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
  29          php_file_utilities::putDataToFile($name, serialize($doc), $writeAttributes);
  30  
  31          return (file_exists($name) && is_writable($name));
  32      } //toCache
  33  
  34      /**
  35      * Unserializes a cached DOMIT! document
  36      * @param string The name of the xml file to be retrieved
  37      * @return Object The retrieved document
  38      */
  39      function &fromCache($xmlFileName) {
  40          require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
  41          require_once (DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
  42  
  43          $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
  44          $fileContents =& php_file_utilities::getDataFromFile($name, 'r');
  45          $newxmldoc =& unserialize($fileContents);
  46  
  47          return $newxmldoc;
  48      } //fromCache
  49  
  50      /**
  51      * Determines whether a cached version of the specified document exists
  52      * @param string The name of the xml file to be retrieved
  53      * @return boolean True if a cache of the specified document exists
  54      */
  55  	function cacheExists($xmlFileName) {
  56          require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
  57  
  58          $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
  59          return file_exists($name);
  60      } //xmlFileName
  61  
  62      /**
  63      * Removes a cache of the specified document
  64      * @param string The name of the xml file to be retrieved
  65      * @return boolean True if a cache has been removed
  66      */
  67  	function removeFromCache($xmlFileName) {
  68          require_once (DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
  69  
  70          $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
  71          return unlink($name);
  72      } //removeFromCache
  73  } //DOMIT_cache
  74  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1