Source for file DefinitionCacheFactory.php

Documentation is available at DefinitionCacheFactory.php

  1. <?php
  2.  
  3. /**
  4.  * Responsible for creating definition caches.
  5.  */
  6. {
  7.     
  8.     protected $caches = array('Serializer' => array());
  9.     protected $implementations = array();
  10.     protected $decorators = array();
  11.     
  12.     /**
  13.      * Initialize default decorators
  14.      */
  15.     public function setup({
  16.         $this->addDecorator('Cleanup');
  17.     }
  18.     
  19.     /**
  20.      * Retrieves an instance of global definition cache factory.
  21.      */
  22.     public static function instance($prototype null{
  23.         static $instance;
  24.         if ($prototype !== null{
  25.             $instance $prototype;
  26.         elseif ($instance === null || $prototype === true{
  27.             $instance new HTMLPurifier_DefinitionCacheFactory();
  28.             $instance->setup();
  29.         }
  30.         return $instance;
  31.     }
  32.     
  33.     /**
  34.      * Registers a new definition cache object
  35.      * @param $short Short name of cache object, for reference
  36.      * @param $long Full class name of cache object, for construction
  37.      */
  38.     public function register($short$long{
  39.         $this->implementations[$short$long;
  40.     }
  41.     
  42.     /**
  43.      * Factory method that creates a cache object based on configuration
  44.      * @param $name Name of definitions handled by cache
  45.      * @param $config Instance of HTMLPurifier_Config
  46.      */
  47.     public function create($type$config{
  48.         $method $config->get('Cache''DefinitionImpl');
  49.         if ($method === null{
  50.             return new HTMLPurifier_DefinitionCache_Null($type);
  51.         }
  52.         if (!empty($this->caches[$method][$type])) {
  53.             return $this->caches[$method][$type];
  54.         }
  55.         if (
  56.           isset($this->implementations[$method]&&
  57.           class_exists($class $this->implementations[$method]false)
  58.         {
  59.             $cache new $class($type);
  60.         else {
  61.             if ($method != 'Serializer'{
  62.                 trigger_error("Unrecognized DefinitionCache $method, using Serializer instead"E_USER_WARNING);
  63.             }
  64.             $cache new HTMLPurifier_DefinitionCache_Serializer($type);
  65.         }
  66.         foreach ($this->decorators as $decorator{
  67.             $new_cache $decorator->decorate($cache);
  68.             // prevent infinite recursion in PHP 4
  69.             unset($cache);
  70.             $cache $new_cache;
  71.         }
  72.         $this->caches[$method][$type$cache;
  73.         return $this->caches[$method][$type];
  74.     }
  75.     
  76.     /**
  77.      * Registers a decorator to add to all new cache objects
  78.      * @param 
  79.      */
  80.     public function addDecorator($decorator{
  81.         if (is_string($decorator)) {
  82.             $class "HTMLPurifier_DefinitionCache_Decorator_$decorator";
  83.             $decorator new $class;
  84.         }
  85.         $this->decorators[$decorator->name$decorator;
  86.     }
  87.     
  88. }

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