aboutsummaryrefslogtreecommitdiff
path: root/lib/less.php/Tree/Operation.php
diff options
context:
space:
mode:
authorderchris2019-02-02 15:35:30 +0100
committerderchris2019-02-02 15:35:30 +0100
commit7ad9f272a482802da2d43fe83841adbe9bcd8cb4 (patch)
tree75b43a2a8c3ab3dbdcb0694d135f4729c90b8af7 /lib/less.php/Tree/Operation.php
parenteb6601b2520d48a0be91634fada0389faadde31d (diff)
update less.php to PHP 7.x compatible fork
Diffstat (limited to 'lib/less.php/Tree/Operation.php')
-rw-r--r--lib/less.php/Tree/Operation.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/less.php/Tree/Operation.php b/lib/less.php/Tree/Operation.php
new file mode 100644
index 0000000..e69e0da
--- /dev/null
+++ b/lib/less.php/Tree/Operation.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Operation
+ *
+ * @package Less
+ * @subpackage tree
+ */
+class Less_Tree_Operation extends Less_Tree{
+
+ public $op;
+ public $operands;
+ public $isSpaced;
+ public $type = 'Operation';
+
+ /**
+ * @param string $op
+ */
+ public function __construct($op, $operands, $isSpaced = false){
+ $this->op = trim($op);
+ $this->operands = $operands;
+ $this->isSpaced = $isSpaced;
+ }
+
+ public function accept($visitor) {
+ $this->operands = $visitor->visitArray($this->operands);
+ }
+
+ public function compile($env){
+ $a = $this->operands[0]->compile($env);
+ $b = $this->operands[1]->compile($env);
+
+
+ if( Less_Environment::isMathOn() ){
+
+ if( $a instanceof Less_Tree_Dimension && $b instanceof Less_Tree_Color ){
+ $a = $a->toColor();
+
+ }elseif( $b instanceof Less_Tree_Dimension && $a instanceof Less_Tree_Color ){
+ $b = $b->toColor();
+
+ }
+
+ if( !method_exists($a,'operate') ){
+ throw new Less_Exception_Compiler("Operation on an invalid type");
+ }
+
+ return $a->operate( $this->op, $b);
+ }
+
+ return new Less_Tree_Operation($this->op, array($a, $b), $this->isSpaced );
+ }
+
+
+ /**
+ * @see Less_Tree::genCSS
+ */
+ public function genCSS( $output ){
+ $this->operands[0]->genCSS( $output );
+ if( $this->isSpaced ){
+ $output->add( " " );
+ }
+ $output->add( $this->op );
+ if( $this->isSpaced ){
+ $output->add( ' ' );
+ }
+ $this->operands[1]->genCSS( $output );
+ }
+
+}