Token.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Abstract base token class that all others inherit from.
  4. */
  5. abstract class HTMLPurifier_Token
  6. {
  7. /**
  8. * Line number node was on in source document. Null if unknown.
  9. * @type int
  10. */
  11. public $line;
  12. /**
  13. * Column of line node was on in source document. Null if unknown.
  14. * @type int
  15. */
  16. public $col;
  17. /**
  18. * Lookup array of processing that this token is exempt from.
  19. * Currently, valid values are "ValidateAttributes" and
  20. * "MakeWellFormed_TagClosedError"
  21. * @type array
  22. */
  23. public $armor = array();
  24. /**
  25. * Used during MakeWellFormed. See Note [Injector skips]
  26. * @type
  27. */
  28. public $skip;
  29. /**
  30. * @type
  31. */
  32. public $rewind;
  33. /**
  34. * @type
  35. */
  36. public $carryover;
  37. /**
  38. * @param string $n
  39. * @return null|string
  40. */
  41. public function __get($n)
  42. {
  43. if ($n === 'type') {
  44. trigger_error('Deprecated type property called; use instanceof', E_USER_NOTICE);
  45. switch (get_class($this)) {
  46. case 'HTMLPurifier_Token_Start':
  47. return 'start';
  48. case 'HTMLPurifier_Token_Empty':
  49. return 'empty';
  50. case 'HTMLPurifier_Token_End':
  51. return 'end';
  52. case 'HTMLPurifier_Token_Text':
  53. return 'text';
  54. case 'HTMLPurifier_Token_Comment':
  55. return 'comment';
  56. default:
  57. return null;
  58. }
  59. }
  60. }
  61. /**
  62. * Sets the position of the token in the source document.
  63. * @param int $l
  64. * @param int $c
  65. */
  66. public function position($l = null, $c = null)
  67. {
  68. $this->line = $l;
  69. $this->col = $c;
  70. }
  71. /**
  72. * Convenience function for DirectLex settings line/col position.
  73. * @param int $l
  74. * @param int $c
  75. */
  76. public function rawPosition($l, $c)
  77. {
  78. if ($c === -1) {
  79. $l++;
  80. }
  81. $this->line = $l;
  82. $this->col = $c;
  83. }
  84. /**
  85. * Converts a token into its corresponding node.
  86. */
  87. abstract public function toNode();
  88. }
  89. // vim: et sw=4 sts=4