Interchange.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Generic schema interchange format that can be converted to a runtime
  4. * representation (HTMLPurifier_ConfigSchema) or HTML documentation. Members
  5. * are completely validated.
  6. */
  7. class HTMLPurifier_ConfigSchema_Interchange
  8. {
  9. /**
  10. * Name of the application this schema is describing.
  11. * @type string
  12. */
  13. public $name;
  14. /**
  15. * Array of Directive ID => array(directive info)
  16. * @type HTMLPurifier_ConfigSchema_Interchange_Directive[]
  17. */
  18. public $directives = array();
  19. /**
  20. * Adds a directive array to $directives
  21. * @param HTMLPurifier_ConfigSchema_Interchange_Directive $directive
  22. * @throws HTMLPurifier_ConfigSchema_Exception
  23. */
  24. public function addDirective($directive)
  25. {
  26. if (isset($this->directives[$i = $directive->id->toString()])) {
  27. throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'");
  28. }
  29. $this->directives[$i] = $directive;
  30. }
  31. /**
  32. * Convenience function to perform standard validation. Throws exception
  33. * on failed validation.
  34. */
  35. public function validate()
  36. {
  37. $validator = new HTMLPurifier_ConfigSchema_Validator();
  38. return $validator->validate($this);
  39. }
  40. }
  41. // vim: et sw=4 sts=4