Goetas\Twital\Attribute\IfAttribute::findPrevElement PHP Method

findPrevElement() public static method

public static findPrevElement ( DOMElement $element )
$element DOMElement
    public static function findPrevElement(\DOMElement $element)
    {
        $prev = $element;
        while ($prev = $prev->previousSibling) {
            if ($prev instanceof \DOMText && trim($prev->textContent)) {
                return null;
            }
            if ($prev instanceof \DOMElement) {
                return $prev;
            }
        }
        return null;
    }

Usage Example

Beispiel #1
0
 public function visit(\DOMAttr $att, Compiler $context)
 {
     $node = $att->ownerElement;
     if (!($prev = IfAttribute::findPrevElement($node))) {
         throw new Exception("The attribute 'elseif' must be the very next sibling of an 'if' of 'elseif' attribute");
     }
     $pi = $context->createControlNode("else");
     $node->parentNode->insertBefore($pi, $node);
     $pi = $context->createControlNode("endif");
     $node->parentNode->insertBefore($pi, $node->nextSibling);
     $node->removeAttributeNode($att);
 }
All Usage Examples Of Goetas\Twital\Attribute\IfAttribute::findPrevElement