HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/DefinitionCache.php
Go to the documentation of this file.
00001 <?php
00002 
00011 abstract class HTMLPurifier_DefinitionCache
00012 {
00013 
00014     public $type;
00015 
00020     public function __construct($type) {
00021         $this->type = $type;
00022     }
00023 
00028     public function generateKey($config) {
00029         return $config->version . ',' . // possibly replace with function calls
00030                $config->getBatchSerial($this->type) . ',' .
00031                $config->get($this->type . '.DefinitionRev');
00032     }
00033 
00040     public function isOld($key, $config) {
00041         if (substr_count($key, ',') < 2) return true;
00042         list($version, $hash, $revision) = explode(',', $key, 3);
00043         $compare = version_compare($version, $config->version);
00044         // version mismatch, is always old
00045         if ($compare != 0) return true;
00046         // versions match, ids match, check revision number
00047         if (
00048             $hash == $config->getBatchSerial($this->type) &&
00049             $revision < $config->get($this->type . '.DefinitionRev')
00050         ) return true;
00051         return false;
00052     }
00053 
00060     public function checkDefType($def) {
00061         if ($def->type !== $this->type) {
00062             trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}");
00063             return false;
00064         }
00065         return true;
00066     }
00067 
00071     abstract public function add($def, $config);
00072 
00076     abstract public function set($def, $config);
00077 
00081     abstract public function replace($def, $config);
00082 
00086     abstract public function get($config);
00087 
00091     abstract public function remove($config);
00092 
00096     abstract public function flush($config);
00097 
00104     abstract public function cleanup($config);
00105 
00106 }
00107 
00108 // vim: et sw=4 sts=4