protected function addTag($type, $name, $pos, $len) { $tag = new Tag($type, $name, $pos, $len); $this->createdTags[] = $tag; if (isset($this->tagsConfig[$name])) { $tag->setFlags($this->tagsConfig[$name]['rules']['flags']); } if (!isset($this->tagsConfig[$name]) && !$tag->isSystemTag()) { $tag->invalidate(); } elseif (!empty($this->tagsConfig[$name]['isDisabled'])) { $this->logger->warn('Tag is disabled', array('tag' => $tag, 'tagName' => $name)); $tag->invalidate(); } elseif ($len < 0 || $pos < 0 || $pos + $len > $this->textLen) { $tag->invalidate(); } else { if ($this->tagStackIsSorted && !empty($this->tagStack) && $tag->getPos() >= \end($this->tagStack)->getPos()) { $this->tagStackIsSorted = \false; } $this->tagStack[] = $tag; } return $tag; }
/** * @testdox isSystemTag() returns true if the tag's name is "pb" */ public function testIsSystemTagParagraphBreak() { $tag = new Tag(Tag::SELF_CLOSING_TAG, 'pb', 0, 0); $this->assertTrue($tag->isSystemTag()); }
/** * Add a tag * * @param integer $type Tag's type * @param string $name Name of the tag * @param integer $pos Position of the tag in the text * @param integer $len Length of text consumed by the tag * @return Tag */ protected function addTag($type, $name, $pos, $len) { // Create the tag $tag = new Tag($type, $name, $pos, $len); // Keep a copy of this tag to destroy its references after processing $this->createdTags[] = $tag; // Set this tag's rules bitfield if (isset($this->tagsConfig[$name])) { $tag->setFlags($this->tagsConfig[$name]['rules']['flags']); } // Invalidate this tag if it's an unknown tag, a disabled tag, if either of its length or // position is negative or if it's out of bounds if (!isset($this->tagsConfig[$name]) && !$tag->isSystemTag()) { $tag->invalidate(); } elseif (!empty($this->tagsConfig[$name]['isDisabled'])) { $this->logger->warn('Tag is disabled', ['tag' => $tag, 'tagName' => $name]); $tag->invalidate(); } elseif ($len < 0 || $pos < 0 || $pos + $len > $this->textLen) { $tag->invalidate(); } else { // If the stack is sorted we check whether this tag should be stored at a lower offset // than the last tag which would mean we need to sort the stack. Note that we cannot use // compareTags() to break ties here because setSortPriority() can be called *after* tags // have been put on the stack, therefore we need to properly sort the stack if the // positions are the same if ($this->tagStackIsSorted && !empty($this->tagStack) && $tag->getPos() >= end($this->tagStack)->getPos()) { $this->tagStackIsSorted = false; } $this->tagStack[] = $tag; } return $tag; }