0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

[3.1.0] Make StringHash system-agnostic.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1621 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-03-22 19:30:37 +00:00
parent ec59062a9d
commit 56cfcba5d1
11 changed files with 12 additions and 63 deletions

View File

@ -57,6 +57,8 @@ require 'HTMLPurifier/Lexer.php';
require 'HTMLPurifier/PercentEncoder.php';
require 'HTMLPurifier/Printer.php';
require 'HTMLPurifier/Strategy.php';
require 'HTMLPurifier/StringHash.php';
require 'HTMLPurifier/StringHashParser.php';
require 'HTMLPurifier/TagTransform.php';
require 'HTMLPurifier/Token.php';
require 'HTMLPurifier/TokenFactory.php';
@ -128,9 +130,6 @@ require 'HTMLPurifier/ConfigDef/Namespace.php';
require 'HTMLPurifier/ConfigSchema/Exception.php';
require 'HTMLPurifier/ConfigSchema/Interchange.php';
require 'HTMLPurifier/ConfigSchema/InterchangeBuilder.php';
require 'HTMLPurifier/ConfigSchema/InterchangeValidator.php';
require 'HTMLPurifier/ConfigSchema/StringHash.php';
require 'HTMLPurifier/ConfigSchema/StringHashParser.php';
require 'HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php';
require 'HTMLPurifier/ConfigSchema/Interchange/Directive.php';
require 'HTMLPurifier/ConfigSchema/Interchange/Id.php';

View File

@ -1,46 +0,0 @@
<?php
/**
* Decorator for interchange that performs validations
*/
class HTMLPurifier_ConfigSchema_InterchangeValidator
{
protected $interchange;
public $namespace;
public $directive;
/**
* @param $interchange Instance of HTMLPurifier_ConfigSchema_Interchange
* to save changes to.
*/
public function __construct($interchange) {
$this->interchange = $interchange;
$this->namespace = new HTMLPurifier_ConfigSchema_Validator_Composite();
$this->directive = new HTMLPurifier_ConfigSchema_Validator_Composite();
}
/**
* Registers a HTMLPurifier_ConfigSchema_Validator for both
* directive and namespace
*/
public function addValidator($validator) {
$this->directive->addValidator($validator);
$this->namespace->addValidator($validator);
}
/**
* Validates and adds a namespace hash
*/
public function addNamespace($hash) {
$this->namespace->validate($hash, $this->interchange);
$this->interchange->addNamespace($hash);
}
/**
* Validates and adds a directive hash
*/
public function addDirective($hash) {
$this->directive->validate($hash, $this->interchange);
$this->interchange->addDirective($hash);
}
}

View File

@ -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 HTMLPurifier_ConfigSchema_StringHash extends ArrayObject
class HTMLPurifier_StringHash extends ArrayObject
{
protected $accessed = array();

View File

@ -20,19 +20,15 @@
* )
*
* We use this as an easy to use file-format for configuration schema
* files.
*
* @todo
* Put this in its own class hierarchy or something; this class
* is usage agnostic.
* files, but the class itself is usage agnostic.
*/
class HTMLPurifier_ConfigSchema_StringHashParser
class HTMLPurifier_StringHashParser
{
public $default = 'ID';
public function parseFile($file) {
if (!file_exists($file)) throw new HTMLPurifier_ConfigSchema_Exception('File ' . $file . ' does not exist');
if (!file_exists($file)) return false;
$fh = fopen($file, 'r');
$state = false;
$single = false;

View File

@ -17,11 +17,11 @@ $FS = new FSTools();
$files = $FS->globr('../library/HTMLPurifier/ConfigSchema/schema', '*.txt');
$parser = new HTMLPurifier_ConfigSchema_StringHashParser();
$parser = new HTMLPurifier_StringHashParser();
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
foreach ($files as $file) {
$builder->build($interchange, $parser->parseFile($file));
$builder->build($interchange, new HTMLPurifier_StringHash($parser->parseFile($file)));
}
$schema_builder = new HTMLPurifier_ConfigSchema_Builder_ConfigSchema();

View File

@ -3,7 +3,7 @@
/**
* @note Sample input files are located in the StringHashParser/ directory.
*/
class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase
class HTMLPurifier_StringHashParserTest extends UnitTestCase
{
/**
@ -12,7 +12,7 @@ class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase
protected $parser;
function setup() {
$this->parser = new HTMLPurifier_ConfigSchema_StringHashParser();
$this->parser = new HTMLPurifier_StringHashParser();
}
/**

View File

@ -1,10 +1,10 @@
<?php
class HTMLPurifier_ConfigSchema_StringHashTest extends UnitTestCase
class HTMLPurifier_StringHashTest extends UnitTestCase
{
public function testUsed() {
$hash = new HTMLPurifier_ConfigSchema_StringHash(array(
$hash = new HTMLPurifier_StringHash(array(
'key' => 'value',
'key2' => 'value2'
));