Removed 'base_path' from AkInstaller->setInstalledVersion because Ak:make_dir can...
[akelos.git] / vendor / domit / xml_domit_cache.php
blobe2950a9d3a9886cac3ffbeb3c9b55cdaf7bf6f62
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 **/
11 /** Extension for cache files */
12 define ('DOMIT_FILE_EXTENSION_CACHE', 'dch');
14 /**
15 * A simple caching mechanism for a DOMIT_Document
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')
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');
28 $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
29 php_file_utilities::putDataToFile($name, serialize($doc), $writeAttributes);
31 return (file_exists($name) && is_writable($name));
32 } //toCache
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
39 function &fromCache($xmlFileName) {
40 require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
41 require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
43 $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
44 $fileContents =& php_file_utilities::getDataFromFile($name, 'r');
45 $newxmldoc =& unserialize($fileContents);
47 return $newxmldoc;
48 } //fromCache
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
55 function cacheExists($xmlFileName) {
56 require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
58 $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
59 return file_exists($name);
60 } //xmlFileName
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
67 function removeFromCache($xmlFileName) {
68 require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
70 $name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
71 return unlink($name);
72 } //removeFromCache
73 } //DOMIT_cache