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