Goetas\Twital\Attribute\AttrAttribute::visit PHP Méthode

visit() public méthode

public visit ( DOMAttr $att, Compiler $context )
$att DOMAttr
$context Goetas\Twital\Compiler
    public function visit(\DOMAttr $att, Compiler $context)
    {
        $node = $att->ownerElement;
        $expressions = ParserHelper::staticSplitExpression($att->value, ",");
        $attributes = array();
        foreach ($expressions as $k => $expression) {
            $expressions[$k] = $attrExpr = self::splitAttrExpression($expression);
            $attNode = null;
            if ($node->hasAttribute($attrExpr['name'])) {
                $attNode = $node->getAttributeNode($attrExpr['name']);
                $node->removeAttributeNode($attNode);
            }
            if ($attrExpr['test'] === "true" || $attrExpr['test'] === "1") {
                unset($expressions[$k]);
                $attributes[$attrExpr['name']] = "[{$attrExpr['expr']}]";
            } elseif ($attNode) {
                $attributes[$attrExpr['name']] = "['" . addcslashes($attNode->value, "'") . "']";
            } else {
                $attributes[$attrExpr['name']] = "[]";
            }
        }
        $varName = self::getVarname($node);
        $code = array();
        $code[] = $context->createControlNode("if {$varName} is not defined");
        $code[] = $context->createControlNode("set {$varName} = {" . ParserHelper::implodeKeyed(",", $attributes, true) . " }");
        $code[] = $context->createControlNode("else");
        $code[] = $context->createControlNode("set {$varName} = {$varName}|merge({" . ParserHelper::implodeKeyed(",", $attributes, true) . "})");
        $code[] = $context->createControlNode("endif");
        foreach ($expressions as $attrExpr) {
            $code[] = $context->createControlNode("if {$attrExpr['test']}");
            $code[] = $context->createControlNode("set {$varName} = {$varName}|merge({ '{$attrExpr['name']}':[{$attrExpr['expr']}] })");
            $code[] = $context->createControlNode("endif");
        }
        $this->addSpecialAttr($node, $varName, $code);
        $node->removeAttributeNode($att);
    }