ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ConfigSchema.php
Go to the documentation of this file.
1 <?php
2 
7 
12  public $defaults = array();
13 
17  public $defaultPlist;
18 
48  public $info = array();
49 
53  static protected $singleton;
54 
55  public function __construct() {
56  $this->defaultPlist = new HTMLPurifier_PropertyList();
57  }
58 
62  public static function makeFromSerial() {
63  $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser');
64  $r = unserialize($contents);
65  if (!$r) {
66  $hash = sha1($contents);
67  trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR);
68  }
69  return $r;
70  }
71 
75  public static function instance($prototype = null) {
76  if ($prototype !== null) {
78  } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) {
80  }
82  }
83 
96  public function add($key, $default, $type, $allow_null) {
97  $obj = new stdclass();
98  $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
99  if ($allow_null) $obj->allow_null = true;
100  $this->info[$key] = $obj;
101  $this->defaults[$key] = $default;
102  $this->defaultPlist->set($key, $default);
103  }
104 
114  public function addValueAliases($key, $aliases) {
115  if (!isset($this->info[$key]->aliases)) {
116  $this->info[$key]->aliases = array();
117  }
118  foreach ($aliases as $alias => $real) {
119  $this->info[$key]->aliases[$alias] = $real;
120  }
121  }
122 
131  public function addAllowedValues($key, $allowed) {
132  $this->info[$key]->allowed = $allowed;
133  }
134 
142  public function addAlias($key, $new_key) {
143  $obj = new stdclass;
144  $obj->key = $new_key;
145  $obj->isAlias = true;
146  $this->info[$key] = $obj;
147  }
148 
152  public function postProcess() {
153  foreach ($this->info as $key => $v) {
154  if (count((array) $v) == 1) {
155  $this->info[$key] = $v->type;
156  } elseif (count((array) $v) == 2 && isset($v->allow_null)) {
157  $this->info[$key] = -$v->type;
158  }
159  }
160  }
161 
162 }
163 
164 // vim: et sw=4 sts=4