HTMLPurifier/ConfigSchema.php Quellcode

ConfigSchema.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
7 {
13  public $defaults = array();
14 
19  public $defaultPlist;
20 
52  public $info = array();
53 
58  protected static $singleton;
59 
60  public function __construct()
61  {
62  $this->defaultPlist = new HTMLPurifier_PropertyList();
63  }
64 
69  public static function makeFromSerial()
70  {
71  $contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser');
72  $r = unserialize($contents);
73  if (!$r) {
74  $hash = sha1($contents);
75  trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR);
76  }
77  return $r;
78  }
79 
85  public static function instance($prototype = null)
86  {
87  if ($prototype !== null) {
89  } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) {
91  }
93  }
94 
106  public function add($key, $default, $type, $allow_null)
107  {
108  $obj = new stdclass();
109  $obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
110  if ($allow_null) {
111  $obj->allow_null = true;
112  }
113  $this->info[$key] = $obj;
114  $this->defaults[$key] = $default;
115  $this->defaultPlist->set($key, $default);
116  }
117 
126  public function addValueAliases($key, $aliases)
127  {
128  if (!isset($this->info[$key]->aliases)) {
129  $this->info[$key]->aliases = array();
130  }
131  foreach ($aliases as $alias => $real) {
132  $this->info[$key]->aliases[$alias] = $real;
133  }
134  }
135 
143  public function addAllowedValues($key, $allowed)
144  {
145  $this->info[$key]->allowed = $allowed;
146  }
147 
153  public function addAlias($key, $new_key)
154  {
155  $obj = new stdclass;
156  $obj->key = $new_key;
157  $obj->isAlias = true;
158  $this->info[$key] = $obj;
159  }
160 
164  public function postProcess()
165  {
166  foreach ($this->info as $key => $v) {
167  if (count((array) $v) == 1) {
168  $this->info[$key] = $v->type;
169  } elseif (count((array) $v) == 2 && isset($v->allow_null)) {
170  $this->info[$key] = -$v->type;
171  }
172  }
173  }
174 }
175 
176 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.