mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 15:48:42 +00:00
Make StringHash compatible for all versions of PHP 5.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1533 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
3ba42106ba
commit
14ef0b75e5
@ -3,6 +3,10 @@
|
|||||||
/**
|
/**
|
||||||
* This is in almost every respect equivalent to an array except
|
* This is in almost every respect equivalent to an array except
|
||||||
* that it keeps track of which keys were accessed.
|
* that it keeps track of which keys were accessed.
|
||||||
|
*
|
||||||
|
* @warning For the sake of backwards compatibility with early versions
|
||||||
|
* 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 ConfigSchema_StringHash extends ArrayObject
|
||||||
{
|
{
|
||||||
|
@ -26,36 +26,36 @@ class ConfigSchema_StringHashAdapter
|
|||||||
if (strpos($hash['ID'], '.') === false) {
|
if (strpos($hash['ID'], '.') === false) {
|
||||||
// This will cause problems if we decide to support nested
|
// This will cause problems if we decide to support nested
|
||||||
// namespaces, but for now it's ok.
|
// namespaces, but for now it's ok.
|
||||||
$schema->addNamespace($hash['ID'], $hash['DESCRIPTION']);
|
$schema->addNamespace($hash->offsetGet('ID'), $hash->offsetGet('DESCRIPTION'));
|
||||||
$this->_findUnused($hash);
|
$this->_findUnused($hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($ns, $directive) = explode('.', $hash['ID'], 2);
|
list($ns, $directive) = explode('.', $hash->offsetGet('ID'), 2);
|
||||||
|
|
||||||
if (isset($hash['TYPE'], $hash['DEFAULT'], $hash['DESCRIPTION'])) {
|
if (isset($hash['TYPE'], $hash['DEFAULT'], $hash['DESCRIPTION'])) {
|
||||||
$type = $hash['TYPE'];
|
$type = $hash->offsetGet('TYPE');
|
||||||
$raw_default = $hash['DEFAULT'];
|
$raw_default = $hash->offsetGet('DEFAULT');
|
||||||
$default = eval("return $raw_default;");
|
$default = eval("return $raw_default;");
|
||||||
$description = $hash['DESCRIPTION'];
|
$description = $hash->offsetGet('DESCRIPTION');
|
||||||
$schema->add($ns, $directive, $default, $type, $description);
|
$schema->add($ns, $directive, $default, $type, $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($hash['ALLOWED'])) {
|
if (isset($hash['ALLOWED'])) {
|
||||||
$raw_allowed = $hash['ALLOWED'];
|
$raw_allowed = $hash->offsetGet('ALLOWED');
|
||||||
$allowed = eval("return array($raw_allowed);");
|
$allowed = eval("return array($raw_allowed);");
|
||||||
$schema->addAllowedValues($ns, $directive, $allowed);
|
$schema->addAllowedValues($ns, $directive, $allowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be after ALLOWED
|
// This must be after ALLOWED
|
||||||
if (isset($hash['VALUE-ALIASES'])) {
|
if (isset($hash['VALUE-ALIASES'])) {
|
||||||
$raw_value_aliases = $hash['VALUE-ALIASES'];
|
$raw_value_aliases = $hash->offsetGet('VALUE-ALIASES');
|
||||||
$value_aliases = eval("return array($raw_value_aliases);");
|
$value_aliases = eval("return array($raw_value_aliases);");
|
||||||
$schema->addValueAliases($ns, $directive, $value_aliases);
|
$schema->addValueAliases($ns, $directive, $value_aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($hash['ALIASES'])) {
|
if (isset($hash['ALIASES'])) {
|
||||||
$raw_aliases = $hash['ALIASES'];
|
$raw_aliases = $hash->offsetGet('ALIASES');
|
||||||
$aliases = preg_split('/\s*,\s*/', $raw_aliases);
|
$aliases = preg_split('/\s*,\s*/', $raw_aliases);
|
||||||
foreach ($aliases as $alias) {
|
foreach ($aliases as $alias) {
|
||||||
list($alias_ns, $alias_directive) = explode('.', $alias, 2);
|
list($alias_ns, $alias_directive) = explode('.', $alias, 2);
|
||||||
|
@ -9,7 +9,7 @@ class ConfigSchema_StringHashTest extends UnitTestCase
|
|||||||
'key2' => 'value2'
|
'key2' => 'value2'
|
||||||
));
|
));
|
||||||
$this->assertIdentical($hash->getAccessed(), array());
|
$this->assertIdentical($hash->getAccessed(), array());
|
||||||
$t = $hash['key'];
|
$t = $hash->offsetGet('key');
|
||||||
$this->assertIdentical($hash->getAccessed(), array('key' => true));
|
$this->assertIdentical($hash->getAccessed(), array('key' => true));
|
||||||
$hash->resetAccessed();
|
$hash->resetAccessed();
|
||||||
$this->assertIdentical($hash->getAccessed(), array());
|
$this->assertIdentical($hash->getAccessed(), array());
|
||||||
|
Loading…
Reference in New Issue
Block a user