friendica/vendor/ezyang/htmlpurifier/library/HTMLPurifier/EntityLookup.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2010-09-08 23:14:17 -04:00
<?php
/**
* Object that provides entity lookup table from entity name to character
*/
2016-02-09 05:06:17 -05:00
class HTMLPurifier_EntityLookup
{
2010-09-08 23:14:17 -04:00
/**
* Assoc array of entity name to character represented.
2016-02-09 05:06:17 -05:00
* @type array
2010-09-08 23:14:17 -04:00
*/
public $table;
/**
* Sets up the entity lookup table from the serialized file contents.
2016-02-09 05:06:17 -05:00
* @param bool $file
2010-09-08 23:14:17 -04: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
*/
2016-02-09 05:06:17 -05:00
public function setup($file = false)
{
2010-09-08 23:14:17 -04:00
if (!$file) {
$file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
}
$this->table = unserialize(file_get_contents($file));
}
/**
* Retrieves sole instance of the object.
2016-02-09 05:06:17 -05:00
* @param bool|HTMLPurifier_EntityLookup $prototype Optional prototype of custom lookup table to overload with.
* @return HTMLPurifier_EntityLookup
2010-09-08 23:14:17 -04:00
*/
2016-02-09 05:06:17 -05:00
public static function instance($prototype = false)
{
2010-09-08 23:14:17 -04:00
// no references, since PHP doesn't copy unless modified
static $instance = null;
if ($prototype) {
$instance = $prototype;
} elseif (!$instance) {
$instance = new HTMLPurifier_EntityLookup();
$instance->setup();
}
return $instance;
}
}
// vim: et sw=4 sts=4