File indexing completed on 2024-12-22 05:36:21
0001 <?php 0002 0003 /** 0004 * Object that provides entity lookup table from entity name to character 0005 */ 0006 class HTMLPurifier_EntityLookup 0007 { 0008 /** 0009 * Assoc array of entity name to character represented. 0010 * @type array 0011 */ 0012 public $table; 0013 0014 /** 0015 * Sets up the entity lookup table from the serialized file contents. 0016 * @param bool $file 0017 * @note The serialized contents are versioned, but were generated 0018 * using the maintenance script generate_entity_file.php 0019 * @warning This is not in constructor to help enforce the Singleton 0020 */ 0021 public function setup($file = false) 0022 { 0023 if (!$file) { 0024 $file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser'; 0025 } 0026 $this->table = unserialize(file_get_contents($file)); 0027 } 0028 0029 /** 0030 * Retrieves sole instance of the object. 0031 * @param bool|HTMLPurifier_EntityLookup $prototype Optional prototype of custom lookup table to overload with. 0032 * @return HTMLPurifier_EntityLookup 0033 */ 0034 public static function instance($prototype = false) 0035 { 0036 // no references, since PHP doesn't copy unless modified 0037 static $instance = null; 0038 if ($prototype) { 0039 $instance = $prototype; 0040 } elseif (!$instance) { 0041 $instance = new HTMLPurifier_EntityLookup(); 0042 $instance->setup(); 0043 } 0044 return $instance; 0045 } 0046 } 0047 0048 // vim: et sw=4 sts=4