A fork of potaka/bbcode to handle future maintenance
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.0KB

  1. <?php
  2. namespace Knockout\BbCode\Tokenizer;
  3. /**
  4. * @author po_taka <angel.koilov@gmail.com>
  5. */
  6. class Tag
  7. {
  8. /**
  9. * @var Tag[]
  10. */
  11. private $tags = [];
  12. private $type;
  13. private $parent = null;
  14. private $text;
  15. /**
  16. * Hold tag argument.
  17. * [url=http://google.bg]search[/url]
  18. * `http://google.bg` is the argument
  19. * @var string
  20. */
  21. private $argument = null;
  22. /**
  23. * @param string|null $type
  24. */
  25. public function __construct($type)
  26. {
  27. $this->type = $type;
  28. }
  29. /**
  30. * @return Tag|null
  31. */
  32. public function getParent()
  33. {
  34. return $this->parent;
  35. }
  36. public function setParent(Tag $parent)
  37. {
  38. $this->parent = $parent;
  39. }
  40. public function addTag(Tag $tag)
  41. {
  42. $tag->setParent($this);
  43. $this->tags[] = $tag;
  44. return $this;
  45. }
  46. /**
  47. * @param Tag $tagToRemove
  48. * @return boolean
  49. */
  50. public function removeTag(Tag $tagToRemove)
  51. {
  52. foreach ($this->tags as $tagkey => $tag) {
  53. if ($tag === $tagToRemove) {
  54. unset($this->tags[$tagkey]);
  55. // reset keys
  56. $this->tags = array_values($this->tags);
  57. return true;
  58. }
  59. }
  60. return false;
  61. }
  62. /**
  63. *
  64. * @param bool $reverse
  65. * @return Tag[]
  66. */
  67. public function getTags($reverse = false)
  68. {
  69. if ($reverse) {
  70. return array_reverse($this->tags);
  71. }
  72. return $this->tags;
  73. }
  74. /**
  75. * @return string|null
  76. */
  77. public function getType()
  78. {
  79. return $this->type;
  80. }
  81. public function getText()
  82. {
  83. return $this->text;
  84. }
  85. public function setText($text)
  86. {
  87. $this->text = $text;
  88. return $this;
  89. }
  90. public function getArgument()
  91. {
  92. return $this->argument;
  93. }
  94. public function setArgumen($argumen)
  95. {
  96. $this->argument = $argumen;
  97. return $this;
  98. }
  99. }