2006-07-23 21:07:30 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Object that provides entity lookup table from entity name to character
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
class HTMLPurifier_EntityLookup
|
|
|
|
{
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Assoc array of entity name to character represented.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @type array
|
2006-08-19 23:06:59 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
public $table;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Sets up the entity lookup table from the serialized file contents.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param bool $file
|
2006-08-19 23:06:59 +00:00
|
|
|
* @note The serialized contents are versioned, but were generated
|
|
|
|
* using the maintenance script generate_entity_file.php
|
|
|
|
* @warning This is not in constructor to help enforce the Singleton
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setup($file = false)
|
|
|
|
{
|
2006-07-23 21:07:30 +00:00
|
|
|
if (!$file) {
|
2007-07-30 16:56:50 +00:00
|
|
|
$file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
|
2006-07-23 21:07:30 +00:00
|
|
|
}
|
|
|
|
$this->table = unserialize(file_get_contents($file));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Retrieves sole instance of the object.
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param bool|HTMLPurifier_EntityLookup $prototype Optional prototype of custom lookup table to overload with.
|
|
|
|
* @return HTMLPurifier_EntityLookup
|
2006-08-19 23:06:59 +00:00
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
public static function instance($prototype = false)
|
|
|
|
{
|
2006-07-23 21:07:30 +00:00
|
|
|
// no references, since PHP doesn't copy unless modified
|
|
|
|
static $instance = null;
|
2006-07-24 11:35:46 +00:00
|
|
|
if ($prototype) {
|
|
|
|
$instance = $prototype;
|
|
|
|
} elseif (!$instance) {
|
2006-07-23 21:07:30 +00:00
|
|
|
$instance = new HTMLPurifier_EntityLookup();
|
2006-07-24 11:35:46 +00:00
|
|
|
$instance->setup();
|
2006-07-23 21:07:30 +00:00
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|