Esempio n. 1
0
 function renderStTag()
 {
     $out = "<" . "?php ";
     $scopeName = "";
     if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) {
         $scopeName = $m[1];
         $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0]));
         $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL);
     } else {
         $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL);
     }
     switch ($this->type) {
         case "each":
             if ($this->var) {
                 $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n";
             } else {
                 $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n";
             }
             $out .= "Hamle\\Scope::add({$this->o}); ";
             break;
         case "if":
             $hsvcomp = new H\Text\Comparison($this->var);
             $out .= "if(" . $hsvcomp->toPHP() . ") {";
             break;
         case "with":
             if ($scopeName) {
                 $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"{$scopeName}\");\n;";
             } else {
                 $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . "{$this->o}->valid()) {\n";
                 $out .= "Hamle\\Scope::add({$this->o});\n;";
             }
             break;
         case "else":
             $out .= "/* else */";
             break;
         case "include":
             $file = $hsv->toHTML();
             if ($file[0] == "#") {
                 $out .= "echo Hamle\\Run::includeFragment(" . $hsv->toPHP() . ");";
             } else {
                 $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");";
             }
             break;
     }
     return $out . ' ?>';
 }
Esempio n. 2
0
 public function testDollarFuncVar1()
 {
     $hs = new Text('$(product.{$tags})', Text::TOKEN_CONTROL);
     $php = $hs->toPHP();
     $this->assertEquals("Hamle\\Run::modelTypeTags(array('product'=>array(0=>Hamle\\Scope::get()->hamleGet('tags'))),array(),0,0)", $php);
 }