ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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)

Definition at line 11 of file InterchangeBuilder.php.

References $varParser.

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

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
$hashInstance of ConfigSchema_StringHash to check.

Definition at line 169 of file InterchangeBuilder.php.

Referenced by build().

169  {
170  $accessed = $hash->getAccessed();
171  foreach ($hash as $k => $v) {
172  if (!isset($accessed[$k])) {
173  trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
174  }
175  }
176  }
+ Here is the caller graph for this function:

◆ build()

HTMLPurifier_ConfigSchema_InterchangeBuilder::build (   $interchange,
  $hash 
)

Builds an interchange object based on a hash.

Parameters
$interchangeHTMLPurifier_ConfigSchema_Interchange object to build
$hashHTMLPurifier_ConfigSchema_StringHash source data

Definition at line 59 of file InterchangeBuilder.php.

References _findUnused(), and buildDirective().

Referenced by buildFile().

59  {
60  if (!$hash instanceof HTMLPurifier_StringHash) {
61  $hash = new HTMLPurifier_StringHash($hash);
62  }
63  if (!isset($hash['ID'])) {
64  throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
65  }
66  if (strpos($hash['ID'], '.') === false) {
67  if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
68  $hash->offsetGet('DESCRIPTION'); // prevent complaining
69  } else {
70  throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
71  }
72  } else {
73  $this->buildDirective($interchange, $hash);
74  }
75  $this->_findUnused($hash);
76  }
_findUnused($hash)
Triggers errors for any unused keys passed in the hash; such keys may indicate typos, missing values, etc.
Exceptions related to configuration schema.
Definition: Exception.php:6
This is in almost every respect equivalent to an array except that it keeps track of which keys were ...
Definition: StringHash.php:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildDir()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildDir (   $interchange,
  $dir = null 
)

Definition at line 21 of file InterchangeBuilder.php.

References $file, and buildFile().

21  {
22  if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
23  if (file_exists($dir . '/info.ini')) {
24  $info = parse_ini_file($dir . '/info.ini');
25  $interchange->name = $info['name'];
26  }
27 
28  $files = array();
29  $dh = opendir($dir);
30  while (false !== ($file = readdir($dh))) {
31  if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
32  continue;
33  }
34  $files[] = $file;
35  }
36  closedir($dh);
37 
38  sort($files);
39  foreach ($files as $file) {
40  $this->buildFile($interchange, $dir . '/' . $file);
41  }
42 
43  return $interchange;
44  }
print $file
+ Here is the call graph for this function:

◆ buildDirective()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildDirective (   $interchange,
  $hash 
)

Definition at line 78 of file InterchangeBuilder.php.

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

Referenced by build().

78  {
80 
81  // These are required elements:
82  $directive->id = $this->id($hash->offsetGet('ID'));
83  $id = $directive->id->toString(); // convenience
84 
85  if (isset($hash['TYPE'])) {
86  $type = explode('/', $hash->offsetGet('TYPE'));
87  if (isset($type[1])) $directive->typeAllowsNull = true;
88  $directive->type = $type[0];
89  } else {
90  throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
91  }
92 
93  if (isset($hash['DEFAULT'])) {
94  try {
95  $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
96  } catch (HTMLPurifier_VarParserException $e) {
97  throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
98  }
99  }
100 
101  if (isset($hash['DESCRIPTION'])) {
102  $directive->description = $hash->offsetGet('DESCRIPTION');
103  }
104 
105  if (isset($hash['ALLOWED'])) {
106  $directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
107  }
108 
109  if (isset($hash['VALUE-ALIASES'])) {
110  $directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
111  }
112 
113  if (isset($hash['ALIASES'])) {
114  $raw_aliases = trim($hash->offsetGet('ALIASES'));
115  $aliases = preg_split('/\s*,\s*/', $raw_aliases);
116  foreach ($aliases as $alias) {
117  $directive->aliases[] = $this->id($alias);
118  }
119  }
120 
121  if (isset($hash['VERSION'])) {
122  $directive->version = $hash->offsetGet('VERSION');
123  }
124 
125  if (isset($hash['DEPRECATED-USE'])) {
126  $directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
127  }
128 
129  if (isset($hash['DEPRECATED-VERSION'])) {
130  $directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
131  }
132 
133  if (isset($hash['EXTERNAL'])) {
134  $directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL')));
135  }
136 
137  $interchange->addDirective($directive);
138  }
Interchange component class describing configuration directives.
Definition: Directive.php:6
Exception type for HTMLPurifier_VarParser.
evalArray($contents)
Evaluates an array PHP code string without array() wrapper.
Exceptions related to configuration schema.
Definition: Exception.php:6
lookup($array)
Converts an array list into a lookup array.
id($id)
Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id object based on a strin...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildFile()

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFile (   $interchange,
  $file 
)

Definition at line 46 of file InterchangeBuilder.php.

References $file, and build().

Referenced by buildDir().

46  {
47  $parser = new HTMLPurifier_StringHashParser();
48  $this->build(
49  $interchange,
50  new HTMLPurifier_StringHash( $parser->parseFile($file) )
51  );
52  }
print $file
build($interchange, $hash)
Builds an interchange object based on a hash.
Parses string hash files.
This is in almost every respect equivalent to an array except that it keeps track of which keys were ...
Definition: StringHash.php:11
+ 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

Definition at line 15 of file InterchangeBuilder.php.

References $builder.

15  {
17  $interchange = new HTMLPurifier_ConfigSchema_Interchange();
18  return $builder->buildDir($interchange, $dir);
19  }
Generic schema interchange format that can be converted to a runtime representation (HTMLPurifier_Con...
Definition: Interchange.php:8
$builder
Definition: parser.php:5

◆ evalArray()

HTMLPurifier_ConfigSchema_InterchangeBuilder::evalArray (   $contents)
protected

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

Definition at line 143 of file InterchangeBuilder.php.

Referenced by buildDirective().

143  {
144  return eval('return array('. $contents .');');
145  }
+ 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.

Definition at line 160 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.

Definition at line 150 of file InterchangeBuilder.php.

References $ret.

Referenced by buildDirective().

150  {
151  $ret = array();
152  foreach ($array as $val) $ret[$val] = true;
153  return $ret;
154  }
+ Here is the caller graph for this function:

Field Documentation

◆ $varParser

HTMLPurifier_ConfigSchema_InterchangeBuilder::$varParser
protected

Used for processing DEFAULT, nothing else.

Definition at line 9 of file InterchangeBuilder.php.

Referenced by __construct().


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