mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 08:21:52 +00:00
[3.1.0] Move ConfigSchema to HTMLPurifier core
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1576 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
d3c04de9dc
commit
002fe649f7
16
TODO
16
TODO
@ -17,8 +17,6 @@ UPCOMING RELEASE
|
||||
|
||||
IMPORTANT
|
||||
- Release candidate, because of the major changes
|
||||
- Move utility classes for ConfigSchema into HTML Purifier itself: they're
|
||||
that important
|
||||
|
||||
DOCUMENTATION
|
||||
- Document new ConfigSchema setup and format; dev-includes.txt is a base
|
||||
@ -31,21 +29,21 @@ IMPORTANT FEATURES
|
||||
- Factor generate-schema-cache.php into a class, so that the maintenance script
|
||||
is as small as possible
|
||||
- Factor out command line parser into its own class, and unit test it
|
||||
- Optimize ConfigSchema by only caching things necessary for runtime
|
||||
- Optimize ConfigSchema by making our runtime class only contain entries for
|
||||
things necessary for operation (NOT descriptions).
|
||||
|
||||
CONFIGDOC
|
||||
- Properly integrate new ConfigSchema system into configdoc (Configdoc
|
||||
- Properly integrate new ConfigSchema system into configdoc. DESCRIPTIONS
|
||||
ARE CURRENTLY BROKEN AND NEED TO BE FIXED!!! (Configdoc
|
||||
should directly read the configuration files, or at the very least should
|
||||
not use static functions)
|
||||
- Reduce code duplication between Serializer and Adapter/ReverseAdapter
|
||||
(we probably want to use ReverseAdapter for the long haul)
|
||||
- Deprecate Serializer in favor of ReverseAdapter
|
||||
- Have configdoc use version and deprecated information (hide deprecated
|
||||
info, for example)
|
||||
- Implement file sniffing for configdoc, so we can easily figure out
|
||||
which files use what configuration
|
||||
- Implement source code sniffing for configdoc, so we can easily figure out
|
||||
which files use what configuration (we'll rely on the $config convention)
|
||||
|
||||
IF IT AIN'T BROKE...
|
||||
- Simplify merge library script by removing recursion? (or other things)
|
||||
- Perhaps replace types with integer identifiers in ConfigSchema? (would be
|
||||
smaller, but not by much).
|
||||
|
||||
|
@ -16,8 +16,7 @@ class HTMLPurifierExtras
|
||||
|
||||
public static function getPath($class) {
|
||||
if (
|
||||
strncmp('FSTools', $class, 7) !== 0 &&
|
||||
strncmp('ConfigSchema', $class, 12) !== 0
|
||||
strncmp('FSTools', $class, 7) !== 0
|
||||
) return false;
|
||||
// Custom implementations can go here
|
||||
// Standard implementation:
|
||||
|
@ -28,12 +28,3 @@ the filesystem. It currently consists of two classes:
|
||||
method imaginable one would need.
|
||||
|
||||
Check the files themselves for more information.
|
||||
|
||||
|
||||
ConfigSchema
|
||||
------------
|
||||
|
||||
ConfigSchema is the next-generation configuration validation system for
|
||||
HTML Purifier, built off of the original HTMLPurifier_ConfigSchema. When
|
||||
complete, it will be used to generate schema files which will then be used
|
||||
to enforce values set to HTMLPurifier_Config.
|
||||
|
@ -121,6 +121,10 @@ require 'HTMLPurifier/ChildDef/Table.php';
|
||||
require 'HTMLPurifier/ConfigDef/Directive.php';
|
||||
require 'HTMLPurifier/ConfigDef/DirectiveAlias.php';
|
||||
require 'HTMLPurifier/ConfigDef/Namespace.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHash.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHashParser.php';
|
||||
require 'HTMLPurifier/ConfigSchema/StringHashReverseAdapter.php';
|
||||
require 'HTMLPurifier/DefinitionCache/Decorator.php';
|
||||
require 'HTMLPurifier/DefinitionCache/Null.php';
|
||||
require 'HTMLPurifier/DefinitionCache/Serializer.php';
|
||||
|
@ -8,7 +8,7 @@
|
||||
* of PHP 5, you must not use the $hash[$key] syntax; if you do
|
||||
* our version of offsetGet is never called.
|
||||
*/
|
||||
class ConfigSchema_StringHash extends ArrayObject
|
||||
class HTMLPurifier_ConfigSchema_StringHash extends ArrayObject
|
||||
{
|
||||
protected $accessed = array();
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
/**
|
||||
* Takes an array of keys to strings, probably generated by
|
||||
* ConfigSchema_StringHashParser
|
||||
* HTMLPurifier_ConfigSchema_StringHashParser
|
||||
*/
|
||||
class ConfigSchema_StringHashAdapter
|
||||
class HTMLPurifier_ConfigSchema_StringHashAdapter
|
||||
{
|
||||
|
||||
/**
|
||||
@ -13,8 +13,8 @@ class ConfigSchema_StringHashAdapter
|
||||
*/
|
||||
public function adapt($hash, $schema) {
|
||||
|
||||
if (! $hash instanceof ConfigSchema_StringHash) {
|
||||
$hash = new ConfigSchema_StringHash($hash);
|
||||
if (! $hash instanceof HTMLPurifier_ConfigSchema_StringHash) {
|
||||
$hash = new HTMLPurifier_ConfigSchema_StringHash($hash);
|
||||
}
|
||||
|
||||
if (!isset($hash['ID'])) {
|
@ -26,19 +26,18 @@
|
||||
* Put this in its own class hierarchy or something; this class
|
||||
* is usage agnostic.
|
||||
*/
|
||||
class ConfigSchema_StringHashParser
|
||||
class HTMLPurifier_ConfigSchema_StringHashParser
|
||||
{
|
||||
|
||||
public $default = 'ID';
|
||||
|
||||
public function parseFile($file) {
|
||||
if (is_string($file)) $file = new FSTools_File($file);
|
||||
if (!$file->exists()) throw new Exception('File does not exist');
|
||||
$file->open('r');
|
||||
if (!file_exists($file)) throw new Exception('File does not exist');
|
||||
$fh = fopen($file, 'r');
|
||||
$state = false;
|
||||
$single = false;
|
||||
$ret = array();
|
||||
while (($line = $file->getLine()) !== false) {
|
||||
while (($line = fgets($fh)) !== false) {
|
||||
$line = rtrim($line, "\n\r");
|
||||
if (!$state && $line === '') continue;
|
||||
if (strncmp('--', $line, 2) === 0) {
|
||||
@ -64,7 +63,7 @@ class ConfigSchema_StringHashParser
|
||||
$ret[$state] .= "$line\n";
|
||||
}
|
||||
}
|
||||
$file->close();
|
||||
fclose($fh);
|
||||
return $ret;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Converts HTMLPurifier_ConfigSchema into a StringHash which can be
|
||||
* easily saved to a file.
|
||||
*/
|
||||
class ConfigSchema_StringHashReverseAdapter
|
||||
class HTMLPurifier_ConfigSchema_StringHashReverseAdapter
|
||||
{
|
||||
|
||||
protected $schema;
|
@ -21,7 +21,7 @@ $namespaces = array();
|
||||
$directives = array();
|
||||
|
||||
// Generate string hashes
|
||||
$parser = new ConfigSchema_StringHashParser();
|
||||
$parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
||||
foreach ($files as $file) {
|
||||
$hash = $parser->parseFile($file);
|
||||
if (strpos($hash['ID'], '.') === false) {
|
||||
@ -31,7 +31,7 @@ foreach ($files as $file) {
|
||||
}
|
||||
}
|
||||
|
||||
$adapter = new ConfigSchema_StringHashAdapter();
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter();
|
||||
$schema = new HTMLPurifier_ConfigSchema();
|
||||
|
||||
foreach ($namespaces as $hash) $adapter->adapt($hash, $schema);
|
||||
|
@ -58,7 +58,7 @@ function saveHash($hash) {
|
||||
}
|
||||
|
||||
$schema = HTMLPurifier_ConfigSchema::instance();
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($schema);
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($schema);
|
||||
|
||||
foreach ($schema->info as $ns => $ns_array) {
|
||||
saveHash($adapter->get($ns));
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
class HTMLPurifier_ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
{
|
||||
function __construct() {
|
||||
generate_mock_once('HTMLPurifier_ConfigSchema');
|
||||
@ -15,7 +15,7 @@ class ConfigSchema_StringHashAdapterTest extends UnitTestCase
|
||||
if (!isset($called[$func])) $called[$func] = 0;
|
||||
$schema->expectAt($called[$func]++, $func, $params);
|
||||
}
|
||||
$adapter = new ConfigSchema_StringHashAdapter();
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashAdapter();
|
||||
$adapter->adapt($input, $schema);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @note Sample input files are located in the StringHashParser/ directory.
|
||||
*/
|
||||
class ConfigSchema_StringHashParserTest extends UnitTestCase
|
||||
class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ class ConfigSchema_StringHashParserTest extends UnitTestCase
|
||||
protected $parser;
|
||||
|
||||
function setup() {
|
||||
$this->parser = new ConfigSchema_StringHashParser();
|
||||
$this->parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
||||
}
|
||||
|
||||
/**
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
class HTMLPurifier_ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
{
|
||||
|
||||
function makeSchema() {
|
||||
@ -17,7 +17,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testNamespace() {
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$result = $adapter->get('Ns');
|
||||
$expect = array(
|
||||
'ID' => 'Ns',
|
||||
@ -27,14 +27,14 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testBadNamespace() {
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$this->expectError("Namespace 'BadNs' doesn't exist in schema");
|
||||
$adapter->get('BadNs');
|
||||
}
|
||||
|
||||
function testDirective() {
|
||||
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
|
||||
$result = $adapter->get('Ns', 'Dir');
|
||||
$expect = array(
|
||||
@ -53,13 +53,13 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function testBadDirective() {
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$this->expectError("Directive 'BadNs.BadDir' doesn't exist in schema");
|
||||
$adapter->get('BadNs', 'BadDir');
|
||||
}
|
||||
|
||||
function assertMethod($func, $input, $expect) {
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$result = $adapter->$func($input);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
@ -85,7 +85,7 @@ class ConfigSchema_StringHashReverseAdapterTest extends UnitTestCase
|
||||
}
|
||||
|
||||
function assertExtraction($desc, $expect_desc, $expect_version) {
|
||||
$adapter = new ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
$adapter = new HTMLPurifier_ConfigSchema_StringHashReverseAdapter($this->makeSchema());
|
||||
list($result_desc, $result_version) = $adapter->extractVersion($desc);
|
||||
$this->assertIdentical($result_desc, $expect_desc);
|
||||
$this->assertIdentical($result_version, $expect_version);
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
class ConfigSchema_StringHashTest extends UnitTestCase
|
||||
class HTMLPurifier_ConfigSchema_StringHashTest extends UnitTestCase
|
||||
{
|
||||
|
||||
public function testUsed() {
|
||||
$hash = new ConfigSchema_StringHash(array(
|
||||
$hash = new HTMLPurifier_ConfigSchema_StringHash(array(
|
||||
'key' => 'value',
|
||||
'key2' => 'value2'
|
||||
));
|
@ -64,6 +64,10 @@ $test_files[] = 'HTMLPurifier/ChildDef/RequiredTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ChildDef/TableTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigSchemaTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashAdapterTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashParserTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigSchema/StringHashTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ConfigTest.php';
|
||||
$test_files[] = 'HTMLPurifier/ContextTest.php';
|
||||
$test_files[] = 'HTMLPurifier/DefinitionCacheFactoryTest.php';
|
||||
@ -136,13 +140,6 @@ if ($csstidy_location) {
|
||||
|
||||
$test_files[] = 'FSTools/FileTest.php';
|
||||
|
||||
// ConfigSchema auxiliary library
|
||||
|
||||
$test_files[] = 'ConfigSchema/StringHashAdapterTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashReverseAdapterTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashParserTest.php';
|
||||
$test_files[] = 'ConfigSchema/StringHashTest.php';
|
||||
|
||||
} // end if ($AC['only-phpt'])
|
||||
|
||||
// PHPT tests
|
||||
|
Loading…
Reference in New Issue
Block a user