Haanga_Compiler::generate_op_ifchanged PHP Method

generate_op_ifchanged() protected method

ifchanged [
protected generate_op_ifchanged ( $details, &$body )
    protected function generate_op_ifchanged($details, &$body)
    {
        static $ifchanged = 0;
        $ifchanged++;
        $var1 = 'ifchanged' . $ifchanged;
        if (!isset($details['check'])) {
            /* ugly */
            $this->ob_start($body);
            $var2 = hvar('buffer' . $this->ob_start);
            $this->generate_op_code($details['body'], $body);
            $this->ob_start--;
            $body->do_if(hexpr(hexec('isset', hvar($var1)), '==', FALSE, '||', hvar($var1), '!=', $var2));
            $this->do_print($body, $var2);
            $body->decl($var1, $var2);
        } else {
            /* beauty :-) */
            foreach ($details['check'] as $id => $type) {
                if (!Haanga_AST::is_var($type)) {
                    throw new Exception("Unexpected string {$type['string']}, expected a varabile");
                }
                $this_expr = hexpr(hexpr(hexec('isset', hvar($var1, $id)), '==', FALSE, '||', hvar($var1, $id), '!=', $type));
                if (isset($expr)) {
                    $this_expr = hexpr($expr, '||', $this_expr);
                }
                $expr = $this_expr;
            }
            $body->do_if($expr);
            $this->generate_op_code($details['body'], $body);
            $body->decl($var1, $details['check']);
        }
        if (isset($details['else'])) {
            $body->do_else();
            $this->generate_op_code($details['else'], $body);
        }
        $body->do_endif();
    }