2008-01-27 19:59:12 +00:00
|
|
|
<?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) {
|
2008-02-05 01:54:20 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:59:12 +00:00
|
|
|
list($ns, $directive) = explode('.', $hash['ID'], 2);
|
2008-02-05 01:54:20 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-27 19:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|