0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 10:45:18 +00:00

Better enforcement of Singleton-ness, by requiring a setup() call after instantiation.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@121 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-07-24 11:35:46 +00:00
parent a55906225a
commit 7a9d39ddcc
2 changed files with 12 additions and 8 deletions

View File

@ -37,16 +37,14 @@ class HTMLPurifier_Definition
static $instance = null; static $instance = null;
if (!$instance) { if (!$instance) {
$instance = new HTMLPurifier_Definition(); $instance = new HTMLPurifier_Definition();
$instance->setup();
} }
return $instance; return $instance;
} }
function HTMLPurifier_Definition() { function HTMLPurifier_Definition() {}
$this->generator = new HTMLPurifier_Generator();
$this->loadData();
}
function loadData() { function setup() {
// emulates the structure of the DTD // emulates the structure of the DTD
// entities: prefixed with e_ and _ replaces . // entities: prefixed with e_ and _ replaces .

View File

@ -4,18 +4,24 @@ class HTMLPurifier_EntityLookup {
var $table; var $table;
function HTMLPurifier_EntityLookup($file = false) { function HTMLPurifier_EntityLookup() {}
// to enforce Singleton-ness
function setup($file = false) {
if (!$file) { if (!$file) {
$file = dirname(__FILE__) . '/EntityLookup/data.txt'; $file = dirname(__FILE__) . '/EntityLookup/data.txt';
} }
$this->table = unserialize(file_get_contents($file)); $this->table = unserialize(file_get_contents($file));
} }
function instance() { function instance($prototype = false) {
// no references, since PHP doesn't copy unless modified // no references, since PHP doesn't copy unless modified
static $instance = null; static $instance = null;
if (!$instance) { if ($prototype) {
$instance = $prototype;
} elseif (!$instance) {
$instance = new HTMLPurifier_EntityLookup(); $instance = new HTMLPurifier_EntityLookup();
$instance->setup();
} }
return $instance; return $instance;
} }