| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once 'HTMLPurifier/DefinitionCache/Serializer.php'; 4 require_once 'HTMLPurifier/DefinitionCache/Null.php'; 5 6 require_once 'HTMLPurifier/DefinitionCache/Decorator.php'; 7 require_once 'HTMLPurifier/DefinitionCache/Decorator/Memory.php'; 8 require_once 'HTMLPurifier/DefinitionCache/Decorator/Cleanup.php'; 9 10 /** 11 * Abstract class representing Definition cache managers that implements 12 * useful common methods and is a factory. 13 * @todo Get some sort of versioning variable so the library can easily 14 * invalidate the cache with a new version 15 * @todo Make the test runner cache aware and allow the user to easily 16 * flush the cache 17 * @todo Create a separate maintenance file advanced users can use to 18 * cache their custom HTMLDefinition, which can be loaded 19 * via a configuration directive 20 * @todo Implement memcached 21 */ 22 class HTMLPurifier_DefinitionCache 23 { 24 25 var $type; 26 27 /** 28 * @param $name Type of definition objects this instance of the 29 * cache will handle. 30 */ 31 function HTMLPurifier_DefinitionCache($type) { 32 $this->type = $type; 33 } 34 35 /** 36 * Generates a unique identifier for a particular configuration 37 * @param Instance of HTMLPurifier_Config 38 */ 39 function generateKey($config) { 40 return $config->version . '-' . // possibly replace with function calls 41 $config->getBatchSerial($this->type) . '-' . 42 $config->get($this->type, 'DefinitionRev'); 43 } 44 45 /** 46 * Tests whether or not a key is old with respect to the configuration's 47 * version and revision number. 48 * @param $key Key to test 49 * @param $config Instance of HTMLPurifier_Config to test against 50 */ 51 function isOld($key, $config) { 52 if (substr_count($key, '-') < 2) return true; 53 list($version, $hash, $revision) = explode('-', $key, 3); 54 $compare = version_compare($version, $config->version); 55 // version mismatch, is always old 56 if ($compare != 0) return true; 57 // versions match, ids match, check revision number 58 if ( 59 $hash == $config->getBatchSerial($this->type) && 60 $revision < $config->get($this->type, 'DefinitionRev') 61 ) return true; 62 return false; 63 } 64 65 /** 66 * Checks if a definition's type jives with the cache's type 67 * @note Throws an error on failure 68 * @param $def Definition object to check 69 * @return Boolean true if good, false if not 70 */ 71 function checkDefType($def) { 72 if ($def->type !== $this->type) { 73 trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); 74 return false; 75 } 76 return true; 77 } 78 79 /** 80 * Adds a definition object to the cache 81 */ 82 function add($def, $config) { 83 trigger_error('Cannot call abstract method', E_USER_ERROR); 84 } 85 86 /** 87 * Unconditionally saves a definition object to the cache 88 */ 89 function set($def, $config) { 90 trigger_error('Cannot call abstract method', E_USER_ERROR); 91 } 92 93 /** 94 * Replace an object in the cache 95 */ 96 function replace($def, $config) { 97 trigger_error('Cannot call abstract method', E_USER_ERROR); 98 } 99 100 /** 101 * Retrieves a definition object from the cache 102 */ 103 function get($config) { 104 trigger_error('Cannot call abstract method', E_USER_ERROR); 105 } 106 107 /** 108 * Removes a definition object to the cache 109 */ 110 function remove($config) { 111 trigger_error('Cannot call abstract method', E_USER_ERROR); 112 } 113 114 /** 115 * Clears all objects from cache 116 */ 117 function flush($config) { 118 trigger_error('Cannot call abstract method', E_USER_ERROR); 119 } 120 121 /** 122 * Clears all expired (older version or revision) objects from cache 123 * @note Be carefuly implementing this method as flush. Flush must 124 * not interfere with other Definition types, and cleanup() 125 * should not be repeatedly called by userland code. 126 */ 127 function cleanup($config) { 128 trigger_error('Cannot call abstract method', E_USER_ERROR); 129 } 130 } 131
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |