[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Operation
   5   *
   6   * @package Less
   7   * @subpackage tree
   8   */
   9  class Less_Tree_Operation extends Less_Tree{
  10  
  11      public $op;
  12      public $operands;
  13      public $isSpaced;
  14      public $type = 'Operation';
  15  
  16      /**
  17       * @param string $op
  18       */
  19  	public function __construct($op, $operands, $isSpaced = false){
  20          $this->op = trim($op);
  21          $this->operands = $operands;
  22          $this->isSpaced = $isSpaced;
  23      }
  24  
  25      public function accept($visitor) {
  26          $this->operands = $visitor->visitArray($this->operands);
  27      }
  28  
  29  	public function compile($env){
  30          $a = $this->operands[0]->compile($env);
  31          $b = $this->operands[1]->compile($env);
  32  
  33  
  34          if( Less_Environment::isMathOn() ){
  35  
  36              if( $a instanceof Less_Tree_Dimension && $b instanceof Less_Tree_Color ){
  37                  $a = $a->toColor();
  38  
  39              }elseif( $b instanceof Less_Tree_Dimension && $a instanceof Less_Tree_Color ){
  40                  $b = $b->toColor();
  41  
  42              }
  43  
  44              if( !method_exists($a,'operate') ){
  45                  throw new Less_Exception_Compiler("Operation on an invalid type");
  46              }
  47  
  48              return $a->operate( $this->op, $b);
  49          }
  50  
  51          return new Less_Tree_Operation($this->op, array($a, $b), $this->isSpaced );
  52      }
  53  
  54  
  55      /**
  56       * @see Less_Tree::genCSS
  57       */
  58      public function genCSS( $output ){
  59          $this->operands[0]->genCSS( $output );
  60          if( $this->isSpaced ){
  61              $output->add( " " );
  62          }
  63          $output->add( $this->op );
  64          if( $this->isSpaced ){
  65              $output->add( ' ' );
  66          }
  67          $this->operands[1]->genCSS( $output );
  68      }
  69  
  70  }


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