0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-23 17:01:51 +00:00
htmlpurifier/extras/ConfigSchema/StringHashAdapter.php

44 lines
1.2 KiB
PHP
Raw Normal View History

<?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);
}
}
}