PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/lessphp/Tree/Operation.php

https://bitbucket.org/moodle/moodle
PHP | 70 lines | 42 code | 16 blank | 12 comment | 7 complexity | dfd3fa0701484387c1a28c9c84e10219 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. /**
  3. * Operation
  4. *
  5. * @package Less
  6. * @subpackage tree
  7. */
  8. class Less_Tree_Operation extends Less_Tree{
  9. public $op;
  10. public $operands;
  11. public $isSpaced;
  12. public $type = 'Operation';
  13. /**
  14. * @param string $op
  15. */
  16. public function __construct($op, $operands, $isSpaced = false){
  17. $this->op = trim($op);
  18. $this->operands = $operands;
  19. $this->isSpaced = $isSpaced;
  20. }
  21. public function accept($visitor) {
  22. $this->operands = $visitor->visitArray($this->operands);
  23. }
  24. public function compile($env){
  25. $a = $this->operands[0]->compile($env);
  26. $b = $this->operands[1]->compile($env);
  27. if( Less_Environment::isMathOn() ){
  28. if( $a instanceof Less_Tree_Dimension && $b instanceof Less_Tree_Color ){
  29. $a = $a->toColor();
  30. }elseif( $b instanceof Less_Tree_Dimension && $a instanceof Less_Tree_Color ){
  31. $b = $b->toColor();
  32. }
  33. if( !method_exists($a,'operate') ){
  34. throw new Less_Exception_Compiler("Operation on an invalid type");
  35. }
  36. return $a->operate( $this->op, $b);
  37. }
  38. return new Less_Tree_Operation($this->op, array($a, $b), $this->isSpaced );
  39. }
  40. /**
  41. * @see Less_Tree::genCSS
  42. */
  43. public function genCSS( $output ){
  44. $this->operands[0]->genCSS( $output );
  45. if( $this->isSpaced ){
  46. $output->add( " " );
  47. }
  48. $output->add( $this->op );
  49. if( $this->isSpaced ){
  50. $output->add( ' ' );
  51. }
  52. $this->operands[1]->genCSS( $output );
  53. }
  54. }