aboutsummaryrefslogtreecommitdiff
path: root/lib/less.php/Tree/Expression.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/Expression.php
parenteb6601b2520d48a0be91634fada0389faadde31d (diff)
update less.php to PHP 7.x compatible fork
Diffstat (limited to '')
-rw-r--r--lib/less.php/Tree/Expression.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/less.php/Tree/Expression.php b/lib/less.php/Tree/Expression.php
new file mode 100644
index 0000000..d834354
--- /dev/null
+++ b/lib/less.php/Tree/Expression.php
@@ -0,0 +1,97 @@
+<?php
+
+/**
+ * Expression
+ *
+ * @package Less
+ * @subpackage tree
+ */
+class Less_Tree_Expression extends Less_Tree{
+
+ public $value = array();
+ public $parens = false;
+ public $parensInOp = false;
+ public $type = 'Expression';
+
+ public function __construct( $value, $parens = null ){
+ $this->value = $value;
+ $this->parens = $parens;
+ }
+
+ public function accept( $visitor ){
+ $this->value = $visitor->visitArray( $this->value );
+ }
+
+ public function compile($env) {
+
+ $doubleParen = false;
+
+ if( $this->parens && !$this->parensInOp ){
+ Less_Environment::$parensStack++;
+ }
+
+ $returnValue = null;
+ if( $this->value ){
+
+ $count = count($this->value);
+
+ if( $count > 1 ){
+
+ $ret = array();
+ foreach($this->value as $e){
+ $ret[] = $e->compile($env);
+ }
+ $returnValue = new Less_Tree_Expression($ret);
+
+ }else{
+
+ if( ($this->value[0] instanceof Less_Tree_Expression) && $this->value[0]->parens && !$this->value[0]->parensInOp ){
+ $doubleParen = true;
+ }
+
+ $returnValue = $this->value[0]->compile($env);
+ }
+
+ } else {
+ $returnValue = $this;
+ }
+
+ if( $this->parens ){
+ if( !$this->parensInOp ){
+ Less_Environment::$parensStack--;
+
+ }elseif( !Less_Environment::isMathOn() && !$doubleParen ){
+ $returnValue = new Less_Tree_Paren($returnValue);
+
+ }
+ }
+ return $returnValue;
+ }
+
+ /**
+ * @see Less_Tree::genCSS
+ */
+ public function genCSS( $output ){
+ $val_len = count($this->value);
+ for( $i = 0; $i < $val_len; $i++ ){
+ $this->value[$i]->genCSS( $output );
+ if( $i + 1 < $val_len ){
+ $output->add( ' ' );
+ }
+ }
+ }
+
+ public function throwAwayComments() {
+
+ if( is_array($this->value) ){
+ $new_value = array();
+ foreach($this->value as $v){
+ if( $v instanceof Less_Tree_Comment ){
+ continue;
+ }
+ $new_value[] = $v;
+ }
+ $this->value = $new_value;
+ }
+ }
+}