Source for file DefinitionCache.php

Documentation is available at DefinitionCache.php

  1. <?php
  2.  
  3. /**
  4.  * Abstract class representing Definition cache managers that implements
  5.  * useful common methods and is a factory.
  6.  * @todo Create a separate maintenance file advanced users can use to
  7.  *        cache their custom HTMLDefinition, which can be loaded
  8.  *        via a configuration directive
  9.  * @todo Implement memcached
  10.  */
  11. {
  12.     
  13.     public $type;
  14.     
  15.     /**
  16.      * @param $name Type of definition objects this instance of the
  17.      *       cache will handle.
  18.      */
  19.     public function __construct($type{
  20.         $this->type = $type;
  21.     }
  22.     
  23.     /**
  24.      * Generates a unique identifier for a particular configuration
  25.      * @param Instance of HTMLPurifier_Config
  26.      */
  27.     public function generateKey($config{
  28.         return $config->version ',' // possibly replace with function calls
  29.                $config->getBatchSerial($this->type',' .
  30.                $config->get($this->type'DefinitionRev');
  31.     }
  32.     
  33.     /**
  34.      * Tests whether or not a key is old with respect to the configuration's
  35.      * version and revision number.
  36.      * @param $key Key to test
  37.      * @param $config Instance of HTMLPurifier_Config to test against
  38.      */
  39.     public function isOld($key$config{
  40.         if (substr_count($key','2return true;
  41.         list($version$hash$revisionexplode(','$key3);
  42.         $compare version_compare($version$config->version);
  43.         // version mismatch, is always old
  44.         if ($compare != 0return true;
  45.         // versions match, ids match, check revision number
  46.         if (
  47.             $hash == $config->getBatchSerial($this->type&&
  48.             $revision $config->get($this->type'DefinitionRev')
  49.         return true;
  50.         return false;
  51.     }
  52.     
  53.     /**
  54.      * Checks if a definition's type jives with the cache's type
  55.      * @note Throws an error on failure
  56.      * @param $def Definition object to check
  57.      * @return Boolean true if good, false if not
  58.      */
  59.     public function checkDefType($def{
  60.         if ($def->type !== $this->type{
  61.             trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}");
  62.             return false;
  63.         }
  64.         return true;
  65.     }
  66.     
  67.     /**
  68.      * Adds a definition object to the cache
  69.      */
  70.     abstract public function add($def, $config);
  71.     
  72.     /**
  73.      * Unconditionally saves a definition object to the cache
  74.      */
  75.     abstract public function set($def, $config);
  76.     
  77.     /**
  78.      * Replace an object in the cache
  79.      */
  80.     abstract public function replace($def, $config);
  81.     
  82.     /**
  83.      * Retrieves a definition object from the cache
  84.      */
  85.     abstract public function get($config);
  86.     
  87.     /**
  88.      * Removes a definition object to the cache
  89.      */
  90.     abstract public function remove($config);
  91.     
  92.     /**
  93.      * Clears all objects from cache
  94.      */
  95.     abstract public function flush($config);
  96.     
  97.     /**
  98.      * Clears all expired (older version or revision) objects from cache
  99.      * @note Be carefuly implementing this method as flush. Flush must
  100.      *       not interfere with other Definition types, and cleanup()
  101.      *       should not be repeatedly called by userland code.
  102.      */
  103.     abstract public function cleanup($config);
  104.     

Documentation generated on Thu, 19 Jun 2008 18:49:01 -0400 by phpDocumentor 1.4.2