00001 <?php
00002
00006 class HTMLPurifier_ConfigSchema {
00007
00012 public $defaults = array();
00013
00043 public $info = array();
00044
00048 static protected $singleton;
00049
00053 public static function makeFromSerial() {
00054 return unserialize(file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser'));
00055 }
00056
00060 public static function instance($prototype = null) {
00061 if ($prototype !== null) {
00062 HTMLPurifier_ConfigSchema::$singleton = $prototype;
00063 } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) {
00064 HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial();
00065 }
00066 return HTMLPurifier_ConfigSchema::$singleton;
00067 }
00068
00081 public function add($namespace, $name, $default, $type, $allow_null) {
00082 $obj = new stdclass();
00083 $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
00084 if ($allow_null) $obj->allow_null = true;
00085 $this->info[$namespace][$name] = $obj;
00086 $this->defaults[$namespace][$name] = $default;
00087 }
00088
00095 public function addNamespace($namespace) {
00096 $this->info[$namespace] = array();
00097 $this->defaults[$namespace] = array();
00098 }
00099
00109 public function addValueAliases($namespace, $name, $aliases) {
00110 if (!isset($this->info[$namespace][$name]->aliases)) {
00111 $this->info[$namespace][$name]->aliases = array();
00112 }
00113 foreach ($aliases as $alias => $real) {
00114 $this->info[$namespace][$name]->aliases[$alias] = $real;
00115 }
00116 }
00117
00126 public function addAllowedValues($namespace, $name, $allowed) {
00127 $this->info[$namespace][$name]->allowed = $allowed;
00128 }
00129
00137 public function addAlias($namespace, $name, $new_namespace, $new_name) {
00138 $obj = new stdclass;
00139 $obj->namespace = $new_namespace;
00140 $obj->name = $new_name;
00141 $obj->isAlias = true;
00142 $this->info[$namespace][$name] = $obj;
00143 }
00144
00148 public function postProcess() {
00149 foreach ($this->info as $namespace => $info) {
00150 foreach ($info as $directive => $v) {
00151 if (count((array) $v) == 1) {
00152 $this->info[$namespace][$directive] = $v->type;
00153 } elseif (count((array) $v) == 2 && isset($v->allow_null)) {
00154 $this->info[$namespace][$directive] = -$v->type;
00155 }
00156 }
00157 }
00158 }
00159
00160
00161
00163 public static function define($namespace, $name, $default, $type, $description) {
00164 HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
00165 $type_values = explode('/', $type, 2);
00166 $type = $type_values[0];
00167 $modifier = isset($type_values[1]) ? $type_values[1] : false;
00168 $allow_null = ($modifier === 'null');
00169 $def = HTMLPurifier_ConfigSchema::instance();
00170 $def->add($namespace, $name, $default, $type, $allow_null);
00171 }
00172
00174 public static function defineNamespace($namespace, $description) {
00175 HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
00176 $def = HTMLPurifier_ConfigSchema::instance();
00177 $def->addNamespace($namespace);
00178 }
00179
00181 public static function defineValueAliases($namespace, $name, $aliases) {
00182 HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
00183 $def = HTMLPurifier_ConfigSchema::instance();
00184 $def->addValueAliases($namespace, $name, $aliases);
00185 }
00186
00188 public static function defineAllowedValues($namespace, $name, $allowed_values) {
00189 HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
00190 $allowed = array();
00191 foreach ($allowed_values as $value) {
00192 $allowed[$value] = true;
00193 }
00194 $def = HTMLPurifier_ConfigSchema::instance();
00195 $def->addAllowedValues($namespace, $name, $allowed);
00196 }
00197
00199 public static function defineAlias($namespace, $name, $new_namespace, $new_name) {
00200 HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
00201 $def = HTMLPurifier_ConfigSchema::instance();
00202 $def->addAlias($namespace, $name, $new_namespace, $new_name);
00203 }
00204
00206 public function validate($a, $b, $c = false) {
00207 trigger_error("HTMLPurifier_ConfigSchema->validate deprecated, use HTMLPurifier_VarParser->parse instead", E_USER_NOTICE);
00208 $parser = new HTMLPurifier_VarParser();
00209 return $parser->parse($a, $b, $c);
00210 }
00211
00215 private static function deprecated($method) {
00216 trigger_error("Static HTMLPurifier_ConfigSchema::$method deprecated, use add*() method instead", E_USER_NOTICE);
00217 }
00218
00219 }
00220
00221