Goetas\Twital\Compiler::compileAttributes PHP Method

compileAttributes() public method

public compileAttributes ( DOMNode $node )
$node DOMNode
    public function compileAttributes(\DOMNode $node)
    {
        $attributes = $this->twital->getAttributes();
        $continueNode = true;
        foreach (iterator_to_array($node->attributes) as $attr) {
            if (!$attr->ownerElement) {
                continue;
            } elseif (isset($attributes[$attr->namespaceURI][$attr->localName])) {
                $attPlugin = $attributes[$attr->namespaceURI][$attr->localName];
            } elseif (isset($attributes[$attr->namespaceURI]['__base__'])) {
                $attPlugin = $attributes[$attr->namespaceURI]['__base__'];
            } elseif ($attr->namespaceURI === Twital::NS) {
                throw new Exception("Can't handle the {$attr->namespaceURI}#{$attr->localName} attribute on {$node->namespaceURI}#{$node->localName} node at line " . $attr->getLineNo());
            } else {
                continue;
            }
            $return = $attPlugin->visit($attr, $this);
            if ($return !== null) {
                $continueNode = $continueNode && !($return & Attribute::STOP_NODE);
                if ($return & Attribute::STOP_ATTRIBUTE) {
                    break;
                }
            }
        }
        return $continueNode;
    }

Usage Example

Exemplo n.º 1
0
 public function visit(\DOMElement $node, Compiler $context)
 {
     if (!$node->hasAttribute("name")) {
         throw new Exception("Name attribute is required");
     }
     $sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
     $node->parentNode->insertBefore($sandbox, $node);
     $node->parentNode->removeChild($node);
     $sandbox->appendChild($node);
     $context->compileAttributes($node);
     $context->compileChilds($node);
     $start = $context->createControlNode("block " . $node->getAttribute("name"));
     $end = $context->createControlNode("endblock");
     $sandbox->insertBefore($start, $sandbox->firstChild);
     $sandbox->appendChild($end);
     DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
     DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
 }
All Usage Examples Of Goetas\Twital\Compiler::compileAttributes