diff --git a/NEWS b/NEWS
index 4c00e02b..fddb12e3 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
! You can now maintain your own configuration schema directories by
creating a config-schema.php file or passing an extra argument. Check
docs/dev-config-schema.html for more details.
+! Added HTMLPurifier_Config->serialize() method, which lets you save away
+ your configuration in a compact serial file, which you can unserialize
+ and use directly without having to go through the overhead of setup.
- Fix bug where URIDefinition would not get cleared if it's directives got
changed.
- Fix fatal error in HTMLPurifier_Encoder on certain platforms (probably NetBSD 5.0)
diff --git a/TODO b/TODO
index 565ad487..1bb707bd 100644
--- a/TODO
+++ b/TODO
@@ -20,9 +20,6 @@ afraid to cast your vote for the next feature to be implemented!
- Think about allowing explicit order of operations hooks for transforms
- Add "register" field to config schemas to eliminate dependence on
naming conventions
-- Make it easy for people to cache their entire configuration (so that
- they have one script they run to change configuration, and then a stub
- loader to get that configuration)
- Add examples to everything (make built-in which also automatically
gives output)
diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php
index 6927f990..91a3cbcb 100644
--- a/library/HTMLPurifier/Config.php
+++ b/library/HTMLPurifier/Config.php
@@ -564,6 +564,17 @@ class HTMLPurifier_Config
trigger_error($msg . $extra, $no);
}
+ /**
+ * Returns a serialized form of the configuration object that can
+ * be reconstituted.
+ */
+ public function serialize() {
+ $this->getDefinition('HTML');
+ $this->getDefinition('CSS');
+ $this->getDefinition('URI');
+ return serialize($this);
+ }
+
}
// vim: et sw=4 sts=4
diff --git a/smoketests/cacheConfig.php b/smoketests/cacheConfig.php
new file mode 100644
index 00000000..2d4ffdda
--- /dev/null
+++ b/smoketests/cacheConfig.php
@@ -0,0 +1,15 @@
+set('HTML.Doctype', 'HTML 4.01 Strict');
+$config->set('HTML.Allowed', 'b,a[href],br');
+$config->set('CSS.AllowTricky', true);
+$config->set('URI.Disable', true);
+$serial = $config->serialize();
+
+$result = unserialize($serial);
+$purifier = new HTMLPurifier($result);
+echo htmlspecialchars($purifier->purify('Bold
no formatting'));
+
diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php
index 103ed5bd..c647c4f8 100644
--- a/tests/HTMLPurifier/ConfigTest.php
+++ b/tests/HTMLPurifier/ConfigTest.php
@@ -451,6 +451,13 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
}
+ function testSerialize() {
+ $config = HTMLPurifier_Config::createDefault();
+ $config->set('HTML.Allowed', 'a');
+ $config2 = unserialize($config->serialize());
+ $this->assertIdentical($config, $config2);
+ }
+
}
// vim: et sw=4 sts=4