[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/lessphp/Tree/ -> Condition.php (source)

   1  <?php
   2  
   3  /**
   4   * Condition
   5   *
   6   * @package Less
   7   * @subpackage tree
   8   */
   9  class Less_Tree_Condition extends Less_Tree{
  10  
  11      public $op;
  12      public $lvalue;
  13      public $rvalue;
  14      public $index;
  15      public $negate;
  16      public $type = 'Condition';
  17  
  18  	public function __construct($op, $l, $r, $i = 0, $negate = false) {
  19          $this->op = trim($op);
  20          $this->lvalue = $l;
  21          $this->rvalue = $r;
  22          $this->index = $i;
  23          $this->negate = $negate;
  24      }
  25  
  26  	public function accept($visitor){
  27          $this->lvalue = $visitor->visitObj( $this->lvalue );
  28          $this->rvalue = $visitor->visitObj( $this->rvalue );
  29      }
  30  
  31      public function compile($env) {
  32          $a = $this->lvalue->compile($env);
  33          $b = $this->rvalue->compile($env);
  34  
  35          switch( $this->op ){
  36              case 'and':
  37                  $result = $a && $b;
  38              break;
  39  
  40              case 'or':
  41                  $result = $a || $b;
  42              break;
  43  
  44              default:
  45                  if( Less_Parser::is_method($a, 'compare') ){
  46                      $result = $a->compare($b);
  47                  }elseif( Less_Parser::is_method($b, 'compare') ){
  48                      $result = $b->compare($a);
  49                  }else{
  50                      throw new Less_Exception_Compiler('Unable to perform comparison', null, $this->index);
  51                  }
  52  
  53                  switch ($result) {
  54                      case -1:
  55                      $result = $this->op === '<' || $this->op === '=<' || $this->op === '<=';
  56                      break;
  57  
  58                      case  0:
  59                      $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<=';
  60                      break;
  61  
  62                      case  1:
  63                      $result = $this->op === '>' || $this->op === '>=';
  64                      break;
  65                  }
  66              break;
  67          }
  68  
  69          return $this->negate ? !$result : $result;
  70      }
  71  
  72  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1