00001 <?php 00002 00006 class HTMLPurifier_ConfigSchema { 00007 00012 public $defaults = array(); 00013 00017 public $defaultPlist; 00018 00048 public $info = array(); 00049 00053 static protected $singleton; 00054 00055 public function __construct() { 00056 $this->defaultPlist = new HTMLPurifier_PropertyList(); 00057 } 00058 00062 public static function makeFromSerial() { 00063 return unserialize(file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser')); 00064 } 00065 00069 public static function instance($prototype = null) { 00070 if ($prototype !== null) { 00071 HTMLPurifier_ConfigSchema::$singleton = $prototype; 00072 } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { 00073 HTMLPurifier_ConfigSchema::$singleton = HTMLPurifier_ConfigSchema::makeFromSerial(); 00074 } 00075 return HTMLPurifier_ConfigSchema::$singleton; 00076 } 00077 00090 public function add($key, $default, $type, $allow_null) { 00091 $obj = new stdclass(); 00092 $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type]; 00093 if ($allow_null) $obj->allow_null = true; 00094 $this->info[$key] = $obj; 00095 $this->defaults[$key] = $default; 00096 $this->defaultPlist->set($key, $default); 00097 } 00098 00108 public function addValueAliases($key, $aliases) { 00109 if (!isset($this->info[$key]->aliases)) { 00110 $this->info[$key]->aliases = array(); 00111 } 00112 foreach ($aliases as $alias => $real) { 00113 $this->info[$key]->aliases[$alias] = $real; 00114 } 00115 } 00116 00125 public function addAllowedValues($key, $allowed) { 00126 $this->info[$key]->allowed = $allowed; 00127 } 00128 00136 public function addAlias($key, $new_key) { 00137 $obj = new stdclass; 00138 $obj->key = $new_key; 00139 $obj->isAlias = true; 00140 $this->info[$key] = $obj; 00141 } 00142 00146 public function postProcess() { 00147 foreach ($this->info as $key => $v) { 00148 if (count((array) $v) == 1) { 00149 $this->info[$key] = $v->type; 00150 } elseif (count((array) $v) == 2 && isset($v->allow_null)) { 00151 $this->info[$key] = -$v->type; 00152 } 00153 } 00154 } 00155 00156 } 00157 00158 // vim: et sw=4 sts=4
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
