ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTMLPurifier_ConfigSchema_InterchangeBuilder Class Reference
+ Collaboration diagram for HTMLPurifier_ConfigSchema_InterchangeBuilder:

Public Member Functions

 __construct ($varParser=null)
 
 buildDir ($interchange, $dir=null)
 
 buildFile ($interchange, $file)
 
 build ($interchange, $hash)
 Builds an interchange object based on a hash. More...
 
 buildDirective ($interchange, $hash)
 

Static Public Member Functions

static buildFromDirectory ($dir=null)
 

Protected Member Functions

 evalArray ($contents)
 Evaluates an array PHP code string without array() wrapper. More...
 
 lookup ($array)
 Converts an array list into a lookup array. More...
 
 id ($id)
 Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id object based on a string Id. More...
 
 _findUnused ($hash)
 Triggers errors for any unused keys passed in the hash; such keys may indicate typos, missing values, etc. More...
 

Protected Attributes

 $varParser
 Used for processing DEFAULT, nothing else. More...
 

Detailed Description

Definition at line 3 of file InterchangeBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_ConfigSchema_InterchangeBuilder::__construct (   $varParser = null)
Parameters
HTMLPurifier_VarParser$varParser

Definition at line 15 of file InterchangeBuilder.php.

16 {
17 $this->varParser = $varParser ? $varParser : new HTMLPurifier_VarParser_Native();
18 }
$varParser
Used for processing DEFAULT, nothing else.
This variable parser uses PHP's internal code engine.
Definition: Native.php:9

References $varParser.

Member Function Documentation

◆ _findUnused()

HTMLPurifier_ConfigSchema_InterchangeBuilder::_findUnused (   $hash)
protected

Triggers errors for any unused keys passed in the hash; such keys may indicate typos, missing values, etc.

Parameters
HTMLPurifier_StringHash$hashHash to check.

Definition at line 215 of file InterchangeBuilder.php.

216 {
217 $accessed = $hash->getAccessed();
218 foreach ($hash as $k => $v) {
219 if (!isset($accessed[$k])) {
220 trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
221 }
222 }
223 }

Referenced by build().

+ Here is the caller graph for this function:

◆ build()

HTMLPurifier_ConfigSchema_InterchangeBuilder::build (   $interchange,
  $hash 
)

Builds an interchange object based on a hash.

Parameters
HTMLPurifier_ConfigSchema_Interchange$interchangeHTMLPurifier_ConfigSchema_Interchange object to build
HTMLPurifier_StringHash$hashsource data
Exceptions
HTMLPurifier_ConfigSchema_Exception

Definition at line 82 of file InterchangeBuilder.php.

83 {
84 if (!$hash instanceof HTMLPurifier_StringHash) {
85 $hash = new HTMLPurifier_StringHash($hash);
86 }
87 if (!isset($hash['ID'])) {
88 throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
89 }
90 if (strpos($hash['ID'], '.') === false) {
91 if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
92 $hash->offsetGet('DESCRIPTION'); // prevent complaining
93 } else {
94 throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
95 }
96 } else {
97 $this->buildDirective($interchange, $hash);
98 }
99 $this->_findUnused($hash);
100 }
Exceptions related to configuration schema.
Definition: Exception.php:7
_findUnused($hash)
Triggers errors for any unused keys passed in the hash; such keys may indicate typos,...
This is in almost every respect equivalent to an array except that it keeps track of which keys were ...
Definition: StringHash.php:12

References _findUnused(), and buildDirective().

Referenced by buildFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildDir()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildDir (   $interchange,
  $dir = null 
)
Parameters
HTMLPurifier_ConfigSchema_Interchange$interchange
string$dir
Returns
HTMLPurifier_ConfigSchema_Interchange

Definition at line 36 of file InterchangeBuilder.php.

37 {
38 if (!$dir) {
39 $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
40 }
41 if (file_exists($dir . '/info.ini')) {
42 $info = parse_ini_file($dir . '/info.ini');
43 $interchange->name = $info['name'];
44 }
45
46 $files = array();
47 $dh = opendir($dir);
48 while (false !== ($file = readdir($dh))) {
49 if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
50 continue;
51 }
52 $files[] = $file;
53 }
54 closedir($dh);
55
56 sort($files);
57 foreach ($files as $file) {
58 $this->buildFile($interchange, $dir . '/' . $file);
59 }
60 return $interchange;
61 }
print $file
$info
Definition: example_052.php:80

References $file, $info, and buildFile().

+ Here is the call graph for this function:

◆ buildDirective()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildDirective (   $interchange,
  $hash 
)
Parameters
HTMLPurifier_ConfigSchema_Interchange$interchange
HTMLPurifier_StringHash$hash
Exceptions
HTMLPurifier_ConfigSchema_Exception

Definition at line 107 of file InterchangeBuilder.php.

108 {
110
111 // These are required elements:
112 $directive->id = $this->id($hash->offsetGet('ID'));
113 $id = $directive->id->toString(); // convenience
114
115 if (isset($hash['TYPE'])) {
116 $type = explode('/', $hash->offsetGet('TYPE'));
117 if (isset($type[1])) {
118 $directive->typeAllowsNull = true;
119 }
120 $directive->type = $type[0];
121 } else {
122 throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
123 }
124
125 if (isset($hash['DEFAULT'])) {
126 try {
127 $directive->default = $this->varParser->parse(
128 $hash->offsetGet('DEFAULT'),
129 $directive->type,
130 $directive->typeAllowsNull
131 );
133 throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
134 }
135 }
136
137 if (isset($hash['DESCRIPTION'])) {
138 $directive->description = $hash->offsetGet('DESCRIPTION');
139 }
140
141 if (isset($hash['ALLOWED'])) {
142 $directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
143 }
144
145 if (isset($hash['VALUE-ALIASES'])) {
146 $directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
147 }
148
149 if (isset($hash['ALIASES'])) {
150 $raw_aliases = trim($hash->offsetGet('ALIASES'));
151 $aliases = preg_split('/\s*,\s*/', $raw_aliases);
152 foreach ($aliases as $alias) {
153 $directive->aliases[] = $this->id($alias);
154 }
155 }
156
157 if (isset($hash['VERSION'])) {
158 $directive->version = $hash->offsetGet('VERSION');
159 }
160
161 if (isset($hash['DEPRECATED-USE'])) {
162 $directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
163 }
164
165 if (isset($hash['DEPRECATED-VERSION'])) {
166 $directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
167 }
168
169 if (isset($hash['EXTERNAL'])) {
170 $directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL')));
171 }
172
173 $interchange->addDirective($directive);
174 }
evalArray($contents)
Evaluates an array PHP code string without array() wrapper.
id($id)
Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id object based on a strin...
lookup($array)
Converts an array list into a lookup array.
Interchange component class describing configuration directives.
Definition: Directive.php:7
Exception type for HTMLPurifier_VarParser.

References evalArray(), id(), and lookup().

Referenced by build().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildFile()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFile (   $interchange,
  $file 
)
Parameters
HTMLPurifier_ConfigSchema_Interchange$interchange
string$file

Definition at line 67 of file InterchangeBuilder.php.

68 {
69 $parser = new HTMLPurifier_StringHashParser();
70 $this->build(
71 $interchange,
72 new HTMLPurifier_StringHash($parser->parseFile($file))
73 );
74 }
build($interchange, $hash)
Builds an interchange object based on a hash.
Parses string hash files.

References $file, and build().

Referenced by buildDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildFromDirectory()

static HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory (   $dir = null)
static
Parameters
string$dir
Returns
HTMLPurifier_ConfigSchema_Interchange

Definition at line 24 of file InterchangeBuilder.php.

25 {
27 $interchange = new HTMLPurifier_ConfigSchema_Interchange();
28 return $builder->buildDir($interchange, $dir);
29 }
Generic schema interchange format that can be converted to a runtime representation (HTMLPurifier_Con...
Definition: Interchange.php:9
$builder
Definition: parser.php:5

References $builder.

◆ evalArray()

HTMLPurifier_ConfigSchema_InterchangeBuilder::evalArray (   $contents)
protected

Evaluates an array PHP code string without array() wrapper.

Parameters
string$contents

Definition at line 180 of file InterchangeBuilder.php.

181 {
182 return eval('return array(' . $contents . ');');
183 }

Referenced by buildDirective().

+ Here is the caller graph for this function:

◆ id()

HTMLPurifier_ConfigSchema_InterchangeBuilder::id (   $id)
protected

Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id object based on a string Id.

Parameters
string$id
Returns
HTMLPurifier_ConfigSchema_Interchange_Id

Definition at line 205 of file InterchangeBuilder.php.

References HTMLPurifier_ConfigSchema_Interchange_Id\make().

Referenced by buildDirective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookup()

HTMLPurifier_ConfigSchema_InterchangeBuilder::lookup (   $array)
protected

Converts an array list into a lookup array.

Parameters
array$array
Returns
array

Definition at line 190 of file InterchangeBuilder.php.

191 {
192 $ret = array();
193 foreach ($array as $val) {
194 $ret[$val] = true;
195 }
196 return $ret;
197 }

References $ret.

Referenced by buildDirective().

+ Here is the caller graph for this function:

Field Documentation

◆ $varParser

HTMLPurifier_ConfigSchema_InterchangeBuilder::$varParser
protected

Used for processing DEFAULT, nothing else.

@type HTMLPurifier_VarParser

Definition at line 10 of file InterchangeBuilder.php.

Referenced by __construct().


The documentation for this class was generated from the following file: