mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 16:31:53 +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:
parent
a55906225a
commit
7a9d39ddcc
@ -37,16 +37,14 @@ class HTMLPurifier_Definition
|
||||
static $instance = null;
|
||||
if (!$instance) {
|
||||
$instance = new HTMLPurifier_Definition();
|
||||
$instance->setup();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function HTMLPurifier_Definition() {
|
||||
$this->generator = new HTMLPurifier_Generator();
|
||||
$this->loadData();
|
||||
}
|
||||
function HTMLPurifier_Definition() {}
|
||||
|
||||
function loadData() {
|
||||
function setup() {
|
||||
// emulates the structure of the DTD
|
||||
|
||||
// entities: prefixed with e_ and _ replaces .
|
||||
|
@ -4,18 +4,24 @@ class HTMLPurifier_EntityLookup {
|
||||
|
||||
var $table;
|
||||
|
||||
function HTMLPurifier_EntityLookup($file = false) {
|
||||
function HTMLPurifier_EntityLookup() {}
|
||||
|
||||
// to enforce Singleton-ness
|
||||
function setup($file = false) {
|
||||
if (!$file) {
|
||||
$file = dirname(__FILE__) . '/EntityLookup/data.txt';
|
||||
}
|
||||
$this->table = unserialize(file_get_contents($file));
|
||||
}
|
||||
|
||||
function instance() {
|
||||
function instance($prototype = false) {
|
||||
// no references, since PHP doesn't copy unless modified
|
||||
static $instance = null;
|
||||
if (!$instance) {
|
||||
if ($prototype) {
|
||||
$instance = $prototype;
|
||||
} elseif (!$instance) {
|
||||
$instance = new HTMLPurifier_EntityLookup();
|
||||
$instance->setup();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user