Changeset 2581

Show
Ignore:
Timestamp:
12/06/07 13:17:18 (5 years ago)
Author:
tasuku
Message:

r309@dhcp158 (orig r52): tasuku | 2007-09-12 17:46:33 +0900
ifequal/ifnotequal tag appeared


Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/php/mumu/trunk/mumu.php

    r2580 r2581  
    194194    'invalidparam_filter_tag' => 'Invalid parameter(s) specified to filter tag', 
    195195    'numofparam_firstof_tag' => 'Number of parameters are invalid to firstof tag', 
     196    'numofparam_ifequal_tag' => 'Number of parameters are invalid to ifequal/ifnotequal tag', 
    196197    'invalidparam_filter_variable' => 'Invalid filter name', 
    197198    'unknown_tag' => 'Unknown tag is specified', 
     
    491492      return $this->nodelist_true->_render($context); 
    492493    } 
     494  } 
     495} 
     496 
     497class MuIfEqualNode extends MuNode { 
     498  function __construct($var1, $var2, $nodelist_true, $nodelist_false, $negate) { 
     499    $this->var1 = $var1; 
     500    $this->var2 = $var2; 
     501    $this->nodelist_true = $nodelist_true; 
     502    $this->nodelist_false = $nodelist_false; 
     503    $this->negate = $negate; 
     504  } 
     505 
     506  public function _render($context) { 
     507    try { 
     508      $val1 = $context->resolve($this->var1); 
     509    } catch (MuValueDoesNotExistException $e) { 
     510    } 
     511    try { 
     512      $val2 = $context->resolve($this->var2); 
     513    } catch (MuValueDoesNotExistException $e) { 
     514    } 
     515    if (($this->negate && $val1 != $val2) || (!$this->negate && $val1 == $val2)) { 
     516      return $this->nodelist_true->_render($context); 
     517    } 
     518    return $this->nodelist_false->_render($context); 
    493519  } 
    494520} 
     
    909935        $node = new MuFirstOfNode($in); 
    910936        break; 
     937      case 'ifequal': 
     938      case 'ifnotequal': 
     939        if (count($in) != 3) { 
     940          return $this->make_errornode('numofparam_ifequal_tag'); 
     941        } 
     942        $this->spos = $lpos + 2; 
     943        $negate = ($in[0] == 'ifnotequal'); 
     944        $endtag = 'end' . $in[0]; 
     945        echo $endtag; 
     946        list($nodelist_true, $nexttag) = 
     947          $this->_parse(array('else', $endtag)); 
     948        if ($nexttag == 'else') { 
     949          list($nodelist_false) = $this->_parse(array($endtag)); 
     950        } else { 
     951          $nodelist_false = new MuNodeList(); 
     952        } 
     953        $node = new MuIfEqualNode($in[1], $in[2], $nodelist_true, $nodelist_false, $negate); 
     954        break; 
    911955      case 'endblock': 
    912956      case 'else': 
     
    914958      case 'endfor': 
    915959      case 'endfilter': 
     960      case 'endifequal': 
     961      case 'endifnotequal': 
    916962        $node = $in[0]; // raw string 
    917963        $this->spos = $lpos + 2;