protected function walkForeach(ForeachNode $foreach)
 {
     $variableNames = array();
     foreach ($foreach->getBody() as $statement) {
         foreach ($this->walk($statement) as $name => $_) {
             $variableNames[$name] = true;
         }
     }
     if ($foreach->hasElseBody()) {
         foreach ($foreach->getElseBody() as $statement) {
             foreach ($this->walk($statement) as $name => $_) {
                 $variableNames[$name] = true;
             }
         }
     }
     return $variableNames;
 }
예제 #2
0
 protected function walkForeach(ForeachNode $foreach)
 {
     $exprSym = $this->gensym();
     $ret = "";
     $ret .= "{$exprSym} = " . $this->walk($foreach->getExpression()) . ";";
     if ($foreach->hasElseBody()) {
         $ret .= "{$exprSym}else = true;";
     }
     if ($foreach->hasName()) {
         $name = $foreach->getName();
     } else {
         $name = $foreach->getValueVariableName();
     }
     $ret .= "\$smarty->foreach->{$name} = (object) array('index' => -1, 'iteration' => 0, 'first' => null, 'last' => null, 'total' => count({$exprSym}));";
     $ret .= "foreach ({$exprSym} as ";
     if ($foreach->getKeyVariableName()) {
         $ret .= "\${$foreach->getKeyVariableName()} => ";
     }
     $ret .= "\${$foreach->getValueVariableName()}) {";
     $ret .= "{$exprSym}else = false;";
     $ret .= "++\$smarty->foreach->{$name}->index;";
     $ret .= "++\$smarty->foreach->{$name}->iteration;";
     $ret .= "\$smarty->foreach->{$name}->first = \$smarty->foreach->{$name}->index == 0;";
     $ret .= "\$smarty->foreach->{$name}->last = \$smarty->foreach->{$name}->iteration == \$smarty->foreach->{$name}->total;";
     $ret .= implode("", $this->walkEach((array) $foreach->getBody()));
     $ret .= "}";
     if ($foreach->hasElseBody()) {
         $ret .= "if({$exprSym}else){" . implode("", $this->walkEach($foreach->getElseBody())) . "}";
     }
     return $ret;
 }
예제 #3
0
 protected function walkForeach(ForeachNode $foreach)
 {
     return new ForeachNode($foreach->getExpression(), $foreach->getName(), $foreach->getKeyVariableName(), $foreach->getValueVariableName(), $this->walkEach($foreach->getBody()), $foreach->hasElseBody() ? $this->walkEach($foreach->getElseBody()) : null);
 }
 protected function walkForeach(ForeachNode $foreach)
 {
     $this->walkEachDisallow($foreach->getBody(), "foreach");
     $this->walkEachDisallow($foreach->getElseBody(), "foreachelse");
 }