Goetas\Twital\Helper\ParserHelper::implodeKeyedDouble PHP Method

implodeKeyedDouble() public static method

public static implodeKeyedDouble ( $glue, array $array, $quoteKeys = false )
$array array
    public static function implodeKeyedDouble($glue, array $array, $quoteKeys = false)
    {
        $a = array();
        foreach ($array as $key => $val) {
            $a[] = ($quoteKeys ? "'{$key}'" : $key) . ":[" . implode(",", $val) . "]";
        }
        return implode($glue, $a);
    }

Usage Example

Beispiel #1
0
 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 (!isset($attributes[$attrExpr['name']])) {
             $attributes[$attrExpr['name']] = array();
         }
         if ($node->hasAttribute($attrExpr['name'])) {
             $attNode = $node->getAttributeNode($attrExpr['name']);
             $node->removeAttributeNode($attNode);
             $attributes[$attrExpr['name']][] = "'" . addcslashes($attNode->value, "'") . "'";
         }
         if ($attrExpr['test'] === "true" || $attrExpr['test'] === "1") {
             unset($expressions[$k]);
             $attributes[$attrExpr['name']][] = $attrExpr['expr'];
         }
     }
     $code = array();
     $varName = self::getVarname($node);
     $code[] = $context->createControlNode("if {$varName} is not defined");
     $code[] = $context->createControlNode("set {$varName} = {" . ParserHelper::implodeKeyedDouble(",", $attributes, true) . " }");
     $code[] = $context->createControlNode("else");
     $code[] = $context->createControlNode("set {$varName} = {$varName}|merge({" . ParserHelper::implodeKeyedDouble(",", $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']}':{$varName}.{$attrExpr['name']}|merge([{$attrExpr['expr']}]) })");
         $code[] = $context->createControlNode("endif");
     }
     $this->addSpecialAttr($node, $varName, $code);
     $node->removeAttributeNode($att);
 }