ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ConfigSchema.php
Go to the documentation of this file.
1<?php
2
7{
13 public $defaults = array();
14
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
Configuration definition, defines directives and their defaults.
Definition: ConfigSchema.php:7
$defaultPlist
The default property list.
static instance($prototype=null)
Retrieves an instance of the application-wide configuration definition.
addValueAliases($key, $aliases)
Defines a directive value alias.
$info
Definition of the directives.
addAllowedValues($key, $allowed)
Defines a set of allowed values for a directive.
addAlias($key, $new_key)
Defines a directive alias for backwards compatibility.
static $singleton
Application-wide singleton @type HTMLPurifier_ConfigSchema.
postProcess()
Replaces any stdclass that only has the type property with type integer.
$defaults
Defaults of the directives and namespaces.
add($key, $default, $type, $allow_null)
Defines a directive for configuration.
static makeFromSerial()
Unserializes the default ConfigSchema.
Generic property list implementation.
Definition: PropertyList.php:7
static $types
Lookup table of allowed types.
Definition: VarParser.php:26
$r
Definition: example_031.php:79