0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-24 01:01:53 +00:00
htmlpurifier/extras/ConfigSchema/StringHashAdapter.php
Edward Z. Yang 2135597553 - Implement StringHash wrapper ArrayObject
- Implement namespace parsing for StringHashAdapter, as well as rudimentary error-checking

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1529 48356398-32a2-884e-a903-53898d9a118a
2008-02-05 01:54:20 +00:00

44 lines
1.2 KiB
PHP

<?php
/**
* Takes an array of keys to strings, probably generated by
* ConfigSchema_StringHashParser
*/
class ConfigSchema_StringHashAdapter
{
/**
* Takes a string hash and calls the appropriate functions in $schema
* based on its values.
*/
public function adapt($hash, $schema) {
if (!isset($hash['ID'])) {
trigger_error('Missing key ID in string hash');
return;
}
// Check namespace:
if (strpos($hash['ID'], '.') === false) {
// This will cause problems if we decide to support nested
// namespaces, but for now it's ok.
$schema->addNamespace($hash['ID'], $hash['DESCRIPTION']);
return;
}
list($ns, $directive) = explode('.', $hash['ID'], 2);
if (isset($hash['DEFAULT'], $hash['DESCRIPTION'], $hash['TYPE'])) {
$raw_default = $hash['DEFAULT'];
$default = eval("return $raw_default;");
$description = $hash['DESCRIPTION'];
$type = $hash['TYPE'];
$schema->add($ns, $directive, $default, $type, $description);
}
}
}