ErrorStruct.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Records errors for particular segments of an HTML document such as tokens,
  4. * attributes or CSS properties. They can contain error structs (which apply
  5. * to components of what they represent), but their main purpose is to hold
  6. * errors applying to whatever struct is being used.
  7. */
  8. class HTMLPurifier_ErrorStruct
  9. {
  10. /**
  11. * Possible values for $children first-key. Note that top-level structures
  12. * are automatically token-level.
  13. */
  14. const TOKEN = 0;
  15. const ATTR = 1;
  16. const CSSPROP = 2;
  17. /**
  18. * Type of this struct.
  19. */
  20. public $type;
  21. /**
  22. * Value of the struct we are recording errors for. There are various
  23. * values for this:
  24. * - TOKEN: Instance of HTMLPurifier_Token
  25. * - ATTR: array('attr-name', 'value')
  26. * - CSSPROP: array('prop-name', 'value')
  27. */
  28. public $value;
  29. /**
  30. * Errors registered for this structure.
  31. */
  32. public $errors = array();
  33. /**
  34. * Child ErrorStructs that are from this structure. For example, a TOKEN
  35. * ErrorStruct would contain ATTR ErrorStructs. This is a multi-dimensional
  36. * array in structure: [TYPE]['identifier']
  37. */
  38. public $children = array();
  39. public function getChild($type, $id) {
  40. if (!isset($this->children[$type][$id])) {
  41. $this->children[$type][$id] = new HTMLPurifier_ErrorStruct();
  42. $this->children[$type][$id]->type = $type;
  43. }
  44. return $this->children[$type][$id];
  45. }
  46. public function addError($severity, $message) {
  47. $this->errors[] = array($severity, $message);
  48. }
  49. }
  50. // vim: et sw=4 sts=4