ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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.
 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.
 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 string Id.
 _findUnused ($hash)
 Triggers errors for any unused keys passed in the hash; such keys may indicate typos, missing values, etc.

Protected Attributes

 $varParser
 Used for processing DEFAULT, nothing else.

Detailed Description

Definition at line 3 of file InterchangeBuilder.php.

Constructor & Destructor Documentation

HTMLPurifier_ConfigSchema_InterchangeBuilder::__construct (   $varParser = null)

Definition at line 11 of file InterchangeBuilder.php.

References $varParser.

{
$this->varParser = $varParser ? $varParser : new HTMLPurifier_VarParser_Native();
}

Member Function Documentation

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().

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

+ Here is the caller graph for this function:

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().

{
if (!$hash instanceof HTMLPurifier_StringHash) {
$hash = new HTMLPurifier_StringHash($hash);
}
if (!isset($hash['ID'])) {
throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
}
if (strpos($hash['ID'], '.') === false) {
if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
$hash->offsetGet('DESCRIPTION'); // prevent complaining
} else {
throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
}
} else {
$this->buildDirective($interchange, $hash);
}
$this->_findUnused($hash);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 21 of file InterchangeBuilder.php.

References $dir, $file, $files, and buildFile().

{
if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
if (file_exists($dir . '/info.ini')) {
$info = parse_ini_file($dir . '/info.ini');
$interchange->name = $info['name'];
}
$files = array();
$dh = opendir($dir);
while (false !== ($file = readdir($dh))) {
if (!$file || $file[0] == '.' || strrchr($file, '.') !== '.txt') {
continue;
}
}
closedir($dh);
sort($files);
foreach ($files as $file) {
$this->buildFile($interchange, $dir . '/' . $file);
}
return $interchange;
}

+ Here is the call graph for this function:

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildDirective (   $interchange,
  $hash 
)

Definition at line 78 of file InterchangeBuilder.php.

References $aliases, $type, evalArray(), id(), and lookup().

Referenced by build().

{
// These are required elements:
$directive->id = $this->id($hash->offsetGet('ID'));
$id = $directive->id->toString(); // convenience
if (isset($hash['TYPE'])) {
$type = explode('/', $hash->offsetGet('TYPE'));
if (isset($type[1])) $directive->typeAllowsNull = true;
$directive->type = $type[0];
} else {
throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
}
if (isset($hash['DEFAULT'])) {
try {
$directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
}
}
if (isset($hash['DESCRIPTION'])) {
$directive->description = $hash->offsetGet('DESCRIPTION');
}
if (isset($hash['ALLOWED'])) {
$directive->allowed = $this->lookup($this->evalArray($hash->offsetGet('ALLOWED')));
}
if (isset($hash['VALUE-ALIASES'])) {
$directive->valueAliases = $this->evalArray($hash->offsetGet('VALUE-ALIASES'));
}
if (isset($hash['ALIASES'])) {
$raw_aliases = trim($hash->offsetGet('ALIASES'));
$aliases = preg_split('/\s*,\s*/', $raw_aliases);
foreach ($aliases as $alias) {
$directive->aliases[] = $this->id($alias);
}
}
if (isset($hash['VERSION'])) {
$directive->version = $hash->offsetGet('VERSION');
}
if (isset($hash['DEPRECATED-USE'])) {
$directive->deprecatedUse = $this->id($hash->offsetGet('DEPRECATED-USE'));
}
if (isset($hash['DEPRECATED-VERSION'])) {
$directive->deprecatedVersion = $hash->offsetGet('DEPRECATED-VERSION');
}
if (isset($hash['EXTERNAL'])) {
$directive->external = preg_split('/\s*,\s*/', trim($hash->offsetGet('EXTERNAL')));
}
$interchange->addDirective($directive);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFile (   $interchange,
  $file 
)

Definition at line 46 of file InterchangeBuilder.php.

References $file, and build().

Referenced by buildDir().

{
$this->build(
$interchange,
new HTMLPurifier_StringHash( $parser->parseFile($file) )
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory (   $dir = null)
static

Definition at line 15 of file InterchangeBuilder.php.

References $builder, and $dir.

{
return $builder->buildDir($interchange, $dir);
}
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().

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

+ Here is the caller graph for this function:

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:

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().

{
$ret = array();
foreach ($array as $val) $ret[$val] = true;
return $ret;
}

+ Here is the caller graph for this function:

Field Documentation

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: