ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_ConfigSchema_Validator Class Reference

Performs validations on HTMLPurifier_ConfigSchema_Interchange. More...

+ Collaboration diagram for HTMLPurifier_ConfigSchema_Validator:

Public Member Functions

 __construct ()
 validate ($interchange)
 Validates a fully-formed interchange object.
 validateId ($id)
 Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.
 validateDirective ($d)
 Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.
 validateDirectiveAllowed ($d)
 Extra validation if $allowed member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
 validateDirectiveValueAliases ($d)
 Extra validation if $valueAliases member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
 validateDirectiveAliases ($d)
 Extra validation if $aliases member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.

Data Fields

 $aliases

Protected Member Functions

 with ($obj, $member)
 Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom for validating simple member variables of objects.
 error ($target, $msg)
 Emits an error, providing helpful context.
 getFormattedContext ()
 Returns a formatted context string.

Protected Attributes

 $interchange
 Easy to access global objects.
 $context = array()
 Context-stack to provide easy to read error messages.
 $parser
 HTMLPurifier_VarParser to test default's type.

Detailed Description

Performs validations on HTMLPurifier_ConfigSchema_Interchange.

Note
If you see '// handled by InterchangeBuilder', that means a design decision in that class would prevent this validation from ever being necessary. We have them anyway, however, for redundancy.

Definition at line 11 of file Validator.php.

Constructor & Destructor Documentation

HTMLPurifier_ConfigSchema_Validator::__construct ( )

Definition at line 29 of file Validator.php.

{
$this->parser = new HTMLPurifier_VarParser();
}

Member Function Documentation

HTMLPurifier_ConfigSchema_Validator::error (   $target,
  $msg 
)
protected

Emits an error, providing helpful context.

Definition at line 191 of file Validator.php.

References getFormattedContext().

Referenced by validate(), validateDirective(), validateDirectiveAliases(), validateDirectiveAllowed(), validateDirectiveValueAliases(), and validateId().

{
if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext();
else $prefix = ucfirst($this->getFormattedContext());
throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::getFormattedContext ( )
protected

Returns a formatted context string.

Definition at line 200 of file Validator.php.

Referenced by error(), and with().

{
return implode(' in ', array_reverse($this->context));
}

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::validate (   $interchange)

Validates a fully-formed interchange object.

Throws an HTMLPurifier_ConfigSchema_Exception if there's a problem.

Definition at line 37 of file Validator.php.

References $interchange, error(), and validateDirective().

{
$this->interchange = $interchange;
$this->aliases = array();
// PHP is a bit lax with integer <=> string conversions in
// arrays, so we don't use the identical !== comparison
foreach ($interchange->directives as $i => $directive) {
$id = $directive->id->toString();
if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
$this->validateDirective($directive);
}
return true;
}

+ Here is the call graph for this function:

HTMLPurifier_ConfigSchema_Validator::validateDirective (   $d)

Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.

Definition at line 71 of file Validator.php.

References $d, HTMLPurifier_VarParser\$stringTypes, HTMLPurifier_VarParser\$types, error(), validateDirectiveAliases(), validateDirectiveAllowed(), validateDirectiveValueAliases(), validateId(), and with().

Referenced by validate().

{
$id = $d->id->toString();
$this->context[] = "directive '$id'";
$this->validateId($d->id);
$this->with($d, 'description')
->assertNotEmpty();
// BEGIN - handled by InterchangeBuilder
$this->with($d, 'type')
->assertNotEmpty();
$this->with($d, 'typeAllowsNull')
->assertIsBool();
try {
// This also tests validity of $d->type
$this->parser->parse($d->default, $d->type, $d->typeAllowsNull);
$this->error('default', 'had error: ' . $e->getMessage());
}
// END - handled by InterchangeBuilder
if (!is_null($d->allowed) || !empty($d->valueAliases)) {
// allowed and valueAliases require that we be dealing with
// strings, so check for that early.
if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) {
$this->error('type', 'must be a string type when used with allowed or value aliases');
}
}
array_pop($this->context);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::validateDirectiveAliases (   $d)

Extra validation if $aliases member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.

Definition at line 159 of file Validator.php.

References $d, error(), validateId(), and with().

Referenced by validateDirective().

{
$this->with($d, 'aliases')
->assertIsArray(); // handled by InterchangeBuilder
$this->context[] = 'aliases';
foreach ($d->aliases as $alias) {
$this->validateId($alias);
$s = $alias->toString();
if (isset($this->interchange->directives[$s])) {
$this->error("alias '$s'", 'collides with another directive');
}
if (isset($this->aliases[$s])) {
$other_directive = $this->aliases[$s];
$this->error("alias '$s'", "collides with alias for directive '$other_directive'");
}
$this->aliases[$s] = $d->id->toString();
}
array_pop($this->context);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::validateDirectiveAllowed (   $d)

Extra validation if $allowed member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.

Definition at line 112 of file Validator.php.

References $d, error(), and with().

Referenced by validateDirective().

{
if (is_null($d->allowed)) return;
$this->with($d, 'allowed')
->assertNotEmpty()
->assertIsLookup(); // handled by InterchangeBuilder
if (is_string($d->default) && !isset($d->allowed[$d->default])) {
$this->error('default', 'must be an allowed value');
}
$this->context[] = 'allowed';
foreach ($d->allowed as $val => $x) {
if (!is_string($val)) $this->error("value $val", 'must be a string');
}
array_pop($this->context);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::validateDirectiveValueAliases (   $d)

Extra validation if $valueAliases member variable of HTMLPurifier_ConfigSchema_Interchange_Directive is defined.

Definition at line 131 of file Validator.php.

References $d, error(), and with().

Referenced by validateDirective().

{
if (is_null($d->valueAliases)) return;
$this->with($d, 'valueAliases')
->assertIsArray(); // handled by InterchangeBuilder
$this->context[] = 'valueAliases';
foreach ($d->valueAliases as $alias => $real) {
if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string');
if ($alias === $real) {
$this->error("alias '$alias'", "must not be an alias to itself");
}
}
if (!is_null($d->allowed)) {
foreach ($d->valueAliases as $alias => $real) {
if (isset($d->allowed[$alias])) {
$this->error("alias '$alias'", 'must not be an allowed value');
} elseif (!isset($d->allowed[$real])) {
$this->error("alias '$alias'", 'must be an alias to an allowed value');
}
}
}
array_pop($this->context);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::validateId (   $id)

Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.

Definition at line 53 of file Validator.php.

References error(), and with().

Referenced by validateDirective(), and validateDirectiveAliases().

{
$id_string = $id->toString();
$this->context[] = "id '$id_string'";
// handled by InterchangeBuilder
$this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id');
}
// keys are now unconstrained (we might want to narrow down to A-Za-z0-9.)
// we probably should check that it has at least one namespace
$this->with($id, 'key')
->assertNotEmpty()
->assertIsString(); // implicit assertIsString handled by InterchangeBuilder
array_pop($this->context);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_ConfigSchema_Validator::with (   $obj,
  $member 
)
protected

Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom for validating simple member variables of objects.

Definition at line 184 of file Validator.php.

References getFormattedContext().

Referenced by validateDirective(), validateDirectiveAliases(), validateDirectiveAllowed(), validateDirectiveValueAliases(), and validateId().

{
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

HTMLPurifier_ConfigSchema_Validator::$aliases

Definition at line 17 of file Validator.php.

HTMLPurifier_ConfigSchema_Validator::$context = array()
protected

Context-stack to provide easy to read error messages.

Definition at line 22 of file Validator.php.

HTMLPurifier_ConfigSchema_Validator::$interchange
protected

Easy to access global objects.

Definition at line 17 of file Validator.php.

Referenced by validate().

HTMLPurifier_ConfigSchema_Validator::$parser
protected

HTMLPurifier_VarParser to test default's type.

Definition at line 27 of file Validator.php.


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