mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 00:41:52 +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:
parent
ec59062a9d
commit
56cfcba5d1
@ -57,6 +57,8 @@ require 'HTMLPurifier/Lexer.php';
|
|||||||
require 'HTMLPurifier/PercentEncoder.php';
|
require 'HTMLPurifier/PercentEncoder.php';
|
||||||
require 'HTMLPurifier/Printer.php';
|
require 'HTMLPurifier/Printer.php';
|
||||||
require 'HTMLPurifier/Strategy.php';
|
require 'HTMLPurifier/Strategy.php';
|
||||||
|
require 'HTMLPurifier/StringHash.php';
|
||||||
|
require 'HTMLPurifier/StringHashParser.php';
|
||||||
require 'HTMLPurifier/TagTransform.php';
|
require 'HTMLPurifier/TagTransform.php';
|
||||||
require 'HTMLPurifier/Token.php';
|
require 'HTMLPurifier/Token.php';
|
||||||
require 'HTMLPurifier/TokenFactory.php';
|
require 'HTMLPurifier/TokenFactory.php';
|
||||||
@ -128,9 +130,6 @@ require 'HTMLPurifier/ConfigDef/Namespace.php';
|
|||||||
require 'HTMLPurifier/ConfigSchema/Exception.php';
|
require 'HTMLPurifier/ConfigSchema/Exception.php';
|
||||||
require 'HTMLPurifier/ConfigSchema/Interchange.php';
|
require 'HTMLPurifier/ConfigSchema/Interchange.php';
|
||||||
require 'HTMLPurifier/ConfigSchema/InterchangeBuilder.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/Builder/ConfigSchema.php';
|
||||||
require 'HTMLPurifier/ConfigSchema/Interchange/Directive.php';
|
require 'HTMLPurifier/ConfigSchema/Interchange/Directive.php';
|
||||||
require 'HTMLPurifier/ConfigSchema/Interchange/Id.php';
|
require 'HTMLPurifier/ConfigSchema/Interchange/Id.php';
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,7 +8,7 @@
|
|||||||
* of PHP 5, you must not use the $hash[$key] syntax; if you do
|
* of PHP 5, you must not use the $hash[$key] syntax; if you do
|
||||||
* our version of offsetGet is never called.
|
* our version of offsetGet is never called.
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_ConfigSchema_StringHash extends ArrayObject
|
class HTMLPurifier_StringHash extends ArrayObject
|
||||||
{
|
{
|
||||||
protected $accessed = array();
|
protected $accessed = array();
|
||||||
|
|
@ -20,19 +20,15 @@
|
|||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
* We use this as an easy to use file-format for configuration schema
|
* We use this as an easy to use file-format for configuration schema
|
||||||
* files.
|
* files, but the class itself is usage agnostic.
|
||||||
*
|
|
||||||
* @todo
|
|
||||||
* Put this in its own class hierarchy or something; this class
|
|
||||||
* is usage agnostic.
|
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_ConfigSchema_StringHashParser
|
class HTMLPurifier_StringHashParser
|
||||||
{
|
{
|
||||||
|
|
||||||
public $default = 'ID';
|
public $default = 'ID';
|
||||||
|
|
||||||
public function parseFile($file) {
|
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');
|
$fh = fopen($file, 'r');
|
||||||
$state = false;
|
$state = false;
|
||||||
$single = false;
|
$single = false;
|
@ -17,11 +17,11 @@ $FS = new FSTools();
|
|||||||
|
|
||||||
$files = $FS->globr('../library/HTMLPurifier/ConfigSchema/schema', '*.txt');
|
$files = $FS->globr('../library/HTMLPurifier/ConfigSchema/schema', '*.txt');
|
||||||
|
|
||||||
$parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
$parser = new HTMLPurifier_StringHashParser();
|
||||||
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
|
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
|
||||||
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||||
foreach ($files as $file) {
|
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();
|
$schema_builder = new HTMLPurifier_ConfigSchema_Builder_ConfigSchema();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* @note Sample input files are located in the StringHashParser/ directory.
|
* @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;
|
protected $parser;
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
$this->parser = new HTMLPurifier_ConfigSchema_StringHashParser();
|
$this->parser = new HTMLPurifier_StringHashParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class HTMLPurifier_ConfigSchema_StringHashTest extends UnitTestCase
|
class HTMLPurifier_StringHashTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testUsed() {
|
public function testUsed() {
|
||||||
$hash = new HTMLPurifier_ConfigSchema_StringHash(array(
|
$hash = new HTMLPurifier_StringHash(array(
|
||||||
'key' => 'value',
|
'key' => 'value',
|
||||||
'key2' => 'value2'
|
'key2' => 'value2'
|
||||||
));
|
));
|
Loading…
Reference in New Issue
Block a user