Compiler.php
protected function compileVariable(Node $node)
    {

        //Attribute-style assignment
        //$variable(a=b, c=d)
        if (count($node->attributes)) {

            if (count($node->children))
                $this->throwException(
                    "A variable node with attributes can't have any children. They are used for array-assignments.",
                    $node
                );

            //Attribute-based assignment
            $array = [];
            foreach ($node->attributes as $attr) {

                $name = $attr->name;
                $value = $attr->value;

                if (!$name)
                    $array[] = $value;
                else {

                    if (isset($array[$name])) {

                        if (is_array($array[$name]))
                            $array[$name][] = $value;
                        else
                            $array[$name] = [$array[$name], $value];
                    } else
                        $array[$name] = $value;
                }
            }

            //In $array we have the final array to assign on the variable, sadly
            //we can't just use var_export, since we might have variables inside
            //the array that shouldn't be converted to strings.
            //We convert it ourself

            return $this->createCode(
                "\$__value = ".$this->exportArray($array)."; "
                ."\${$node->name} = isset(\${$node->name}) ? array_replace_recursive(\${$node->name}, \$__value) : \$__value; "
                ."unset(\$__value);"
            );
        }

        if (!count($node->children)) {

            //No children, this is simple variable output (Escaped!)
            return $this->createShortCode(
                "htmlentities(\${$node->name}, \\ENT_QUOTES, '".$this->options['escape_charset']."')"
            );
        }

        if ($node->children[0]->type !== 'expression') {

            $this->throwException(
                'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \'some value\'`)',
                $node
            );
        }

        return $this->createCode("\${$node->name} = ".$node->children[0]->value);
    }
protected function compileVariable(Node $node)
    {

        //Attribute-style assignment
        //$variable(a=b, c=d)
        if (count($node->attributes)) {

            if (count($node->children))
                $this->throwException(
                    "A variable node with attributes can't have any children. They are used for array-assignments.",
                    $node
                );

            //Attribute-based assignment
            $array = [];
            foreach ($node->attributes as $attr) {

                $name = $attr->name;
                $value = $attr->value;

                if (!$name)
                    $array[] = $value;
                else {

                    if (isset($array[$name])) {

                        if (is_array($array[$name]))
                            $array[$name][] = $value;
                        else
                            $array[$name] = [$array[$name], $value];
                    } else
                        $array[$name] = $value;
                }
            }

            //In $array we have the final array to assign on the variable, sadly
            //we can't just use var_export, since we might have variables inside
            //the array that shouldn't be converted to strings.
            //We convert it ourself

            return $this->createCode(
                "\$__value = ".$this->exportArray($array)."; "
                ."\${$node->name} = isset(\${$node->name}) ? array_replace_recursive(\${$node->name}, \$__value) : \$__value; "
                ."unset(\$__value);"
            );
        }

        if (!count($node->children)) {

            //No children, this is simple variable output (Escaped!)
            return $this->createShortCode(
                "htmlentities(\${$node->name}, \\ENT_QUOTES, '".$this->options['escape_charset']."')"
            );
        }

        if ($node->children[0]->type !== 'expression') {

            $this->throwException(
                'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \'some value\'`)',
                $node
            );
        }

        return $this->createCode("\${$node->name} = ".$node->children[0]->value);
    }
protected function compileVariable ( Node $ node ) { //Attribute-style assignment //$variable(a=b, c=d) if ( count ( $ node -> attributes ) ) { if ( count ( $ node -> children ) ) $ this -> throwException ( "A variable node with attributes can't have any children. They are used for array-assignments." , $ node ) ; //Attribute-based assignment $ array = [ ] ; foreach ( $ node -> attributes as $ attr ) { $ name = $ attr -> name ; $ value = $ attr -> value ; if ( ! $ name ) $ array [ ] = $ value ; else { if ( isset ( $ array [ $ name ] ) ) { if ( is_array ( $ array [ $ name ] ) ) $ array [ $ name ] [ ] = $ value ; else $ array [ $ name ] = [ $ array [ $ name ] , $ value ] ; } else $ array [ $ name ] = $ value ; } } //In $array we have the final array to assign on the variable, sadly //we can't just use var_export, since we might have variables inside //the array that shouldn't be converted to strings. //We convert it ourself return $ this -> createCode ( "\$__value = " . $ this -> exportArray ( $ array ) . "; " . "\${$node->name} = isset(\${$node->name}) ? array_replace_recursive(\${$node->name}, \$__value) : \$__value; " . "unset(\$__value);" ) ; } if ( ! count ( $ node -> children ) ) { //No children, this is simple variable output (Escaped!) return $ this -> createShortCode ( "htmlentities(\${$node->name}, \\ENT_QUOTES, '" . $ this -> options [ 'escape_charset' ] . "')" ) ; } if ( $ node -> children [ 0 ] -> type !== 'expression' ) { $ this -> throwException ( 'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \'some value\'`)' , $ node ) ; } return $ this -> createCode ( "\${$node->name} = " . $ node -> children [ 0 ] -> value ) ; }
Compiles a variable-node into PHTML.

@param Node $node the variable node to compile

@return string The compiled PHTML
@throws Exception
Compiles a variable - node into PHTML .