protected function pushContext(Tag $tag) { $tagName = $tag->getName(); $tagFlags = $tag->getFlags(); $tagConfig = $this->tagsConfig[$tagName]; ++$this->cntTotal[$tagName]; if ($tag->isSelfClosingTag()) { return; } $allowed = array(); if ($tagFlags & self::RULE_IS_TRANSPARENT) { foreach ($this->context['allowed'] as $k => $v) { $allowed[] = $tagConfig['allowed'][$k] & $v; } } else { foreach ($this->context['allowed'] as $k => $v) { $allowed[] = $tagConfig['allowed'][$k] & ($v & 0xff00 | $v >> 8); } } $flags = $tagFlags | $this->context['flags'] & self::RULES_INHERITANCE; if ($flags & self::RULE_DISABLE_AUTO_BR) { $flags &= ~self::RULE_ENABLE_AUTO_BR; } ++$this->cntOpen[$tagName]; $this->openTags[] = $tag; $this->context = array('allowed' => $allowed, 'flags' => $flags, 'inParagraph' => \false, 'parentContext' => $this->context); }
/** * @testdox removeFlags() can be called on flags that haven't been set */ public function testRemoveFlagsUnset() { $tag = new Tag(Tag::START_TAG, 'X', 0, 0); $tag->setFlags(2); $tag->removeFlags(5); $this->assertSame(2, $tag->getFlags()); }
/** * Update counters and replace current context with a new context based on given tag * * If given tag is a self-closing tag, the context won't change * * @param Tag $tag Start tag (including self-closing) * @return void */ protected function pushContext(Tag $tag) { $tagName = $tag->getName(); $tagFlags = $tag->getFlags(); $tagConfig = $this->tagsConfig[$tagName]; ++$this->cntTotal[$tagName]; // If this is a self-closing tag, the context remains the same if ($tag->isSelfClosingTag()) { return; } // Recompute the allowed tags $allowed = []; if ($tagFlags & self::RULE_IS_TRANSPARENT) { foreach ($this->context['allowed'] as $k => $v) { $allowed[] = $tagConfig['allowed'][$k] & $v; } } else { foreach ($this->context['allowed'] as $k => $v) { $allowed[] = $tagConfig['allowed'][$k] & ($v & 0xff00 | $v >> 8); } } // Use this tag's flags as a base for this context and add inherited rules $flags = $tagFlags | $this->context['flags'] & self::RULES_INHERITANCE; // RULE_DISABLE_AUTO_BR turns off RULE_ENABLE_AUTO_BR if ($flags & self::RULE_DISABLE_AUTO_BR) { $flags &= ~self::RULE_ENABLE_AUTO_BR; } ++$this->cntOpen[$tagName]; $this->openTags[] = $tag; $this->context = ['allowed' => $allowed, 'flags' => $flags, 'inParagraph' => false, 'parentContext' => $this->context]; }