From 8d0d0d1a03e1f47c5b9ac08fe8211a16dba10f8d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 22 May 2008 04:34:19 +0000 Subject: [PATCH] [3.1.1] construct() to setup() in HTMLModules git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1760 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 3 +++ TODO | 1 + library/HTMLPurifier/HTMLModule.php | 9 +++++++++ library/HTMLPurifier/HTMLModule/Tidy.php | 2 +- library/HTMLPurifier/HTMLModuleManager.php | 5 ++--- tests/HTMLPurifier/HTMLModule/TidyTest.php | 12 ++++++------ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 327bee30..1bb85e67 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier to __construct($min, $max). __construct(true) is equivalent to __construct('0'). . Added HTMLPurifier_AttrDef_Switch class +. Rename HTMLPurifier_HTMLModule_Tidy->construct() to setup(), and bubble + up inheritance hierarchy to HTMLPurifier_HTMLModule. All HTMLModules + get this called with the configuration object. 3.1.0, released 2008-05-18 # Unnecessary references to objects (vestiges of PHP4) removed from method diff --git a/TODO b/TODO index ad5e080d..96bd20f0 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,7 @@ afraid to cast your vote for the next feature to be implemented! two separate directives due to our architecture.) - Investigate how early internal structures can be accessed; this would prevent structures from being parsed and serialized multiple times. +- Figure out how to simultaneously set %CSS.Trusted and %HTML.Trusted (?) FUTURE VERSIONS --------------- diff --git a/library/HTMLPurifier/HTMLModule.php b/library/HTMLPurifier/HTMLModule.php index db78983b..a6241f06 100644 --- a/library/HTMLPurifier/HTMLModule.php +++ b/library/HTMLPurifier/HTMLModule.php @@ -222,5 +222,14 @@ class HTMLPurifier_HTMLModule } return $ret; } + + /** + * Lazy load construction of the module after determining whether + * or not it's needed, and also when a finalized configuration object + * is available. + * @param $config Instance of HTMLPurifier_Config + */ + public function setup($config) {} + } diff --git a/library/HTMLPurifier/HTMLModule/Tidy.php b/library/HTMLPurifier/HTMLModule/Tidy.php index 1606ffc6..a95d453b 100644 --- a/library/HTMLPurifier/HTMLModule/Tidy.php +++ b/library/HTMLPurifier/HTMLModule/Tidy.php @@ -35,7 +35,7 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule * @todo Wildcard matching and error reporting when an added or * subtracted fix has no effect. */ - public function construct($config) { + public function setup($config) { // create fixes, initialize fixesForLevel $fixes = $this->makeFixes(); diff --git a/library/HTMLPurifier/HTMLModuleManager.php b/library/HTMLPurifier/HTMLModuleManager.php index 612c3c01..1a012fe5 100644 --- a/library/HTMLPurifier/HTMLModuleManager.php +++ b/library/HTMLPurifier/HTMLModuleManager.php @@ -223,13 +223,12 @@ class HTMLPurifier_HTMLModuleManager foreach ($modules as $module) { $this->processModule($module); + $this->modules[$module]->setup($config); } foreach ($this->doctype->tidyModules as $module) { $this->processModule($module); - if (method_exists($this->modules[$module], 'construct')) { - $this->modules[$module]->construct($config); - } + $this->modules[$module]->setup($config); } // setup lookup table based on all valid modules diff --git a/tests/HTMLPurifier/HTMLModule/TidyTest.php b/tests/HTMLPurifier/HTMLModule/TidyTest.php index 62157660..4250b49a 100644 --- a/tests/HTMLPurifier/HTMLModule/TidyTest.php +++ b/tests/HTMLPurifier/HTMLModule/TidyTest.php @@ -38,7 +38,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness } - function test_construct() { + function test_setup() { $i = 0; // counter, helps us isolate expectations @@ -63,7 +63,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness 'HTML.TidyLevel' => 'none' )); $module->expectAt($i++, 'populate', array(array())); - $module->construct($config); + $module->setup($config); // basic levels @@ -74,7 +74,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness 'light-fix-1' => $lf1, 'light-fix-2' => $lf2 ))); - $module->construct($config); + $module->setup($config); $config = HTMLPurifier_Config::create(array( 'HTML.TidyLevel' => 'heavy' @@ -87,7 +87,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness 'heavy-fix-1' => $hf1, 'heavy-fix-2' => $hf2 ))); - $module->construct($config); + $module->setup($config); // fine grained tuning @@ -99,7 +99,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness 'light-fix-1' => $lf1, 'medium-fix-1' => $mf1 ))); - $module->construct($config); + $module->setup($config); $config = HTMLPurifier_Config::create(array( 'HTML.TidyLevel' => 'medium', @@ -109,7 +109,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness 'light-fix-2' => $lf2, 'medium-fix-2' => $mf2 ))); - $module->construct($config); + $module->setup($config); } -- 2.11.4.GIT