aboutsummaryrefslogtreecommitdiff
path: root/lib/less.php/Visitor/joinSelector.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/Visitor/joinSelector.php
parenteb6601b2520d48a0be91634fada0389faadde31d (diff)
update less.php to PHP 7.x compatible fork
Diffstat (limited to '')
-rw-r--r--lib/less.php/Visitor/joinSelector.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/less.php/Visitor/joinSelector.php b/lib/less.php/Visitor/joinSelector.php
new file mode 100644
index 0000000..f62af1a
--- /dev/null
+++ b/lib/less.php/Visitor/joinSelector.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Join Selector Visitor
+ *
+ * @package Less
+ * @subpackage visitor
+ */
+class Less_Visitor_joinSelector extends Less_Visitor{
+
+ public $contexts = array( array() );
+
+ /**
+ * @param Less_Tree_Ruleset $root
+ */
+ public function run( $root ){
+ return $this->visitObj($root);
+ }
+
+ public function visitRule( $ruleNode, &$visitDeeper ){
+ $visitDeeper = false;
+ }
+
+ public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){
+ $visitDeeper = false;
+ }
+
+ public function visitRuleset( $rulesetNode ){
+
+ $paths = array();
+
+ if( !$rulesetNode->root ){
+ $selectors = array();
+
+ if( $rulesetNode->selectors && $rulesetNode->selectors ){
+ foreach($rulesetNode->selectors as $selector){
+ if( $selector->getIsOutput() ){
+ $selectors[] = $selector;
+ }
+ }
+ }
+
+ if( !$selectors ){
+ $rulesetNode->selectors = null;
+ $rulesetNode->rules = null;
+ }else{
+ $context = end($this->contexts); //$context = $this->contexts[ count($this->contexts) - 1];
+ $paths = $rulesetNode->joinSelectors( $context, $selectors);
+ }
+
+ $rulesetNode->paths = $paths;
+ }
+
+ $this->contexts[] = $paths; //different from less.js. Placed after joinSelectors() so that $this->contexts will get correct $paths
+ }
+
+ public function visitRulesetOut(){
+ array_pop($this->contexts);
+ }
+
+ public function visitMedia($mediaNode) {
+ $context = end($this->contexts); //$context = $this->contexts[ count($this->contexts) - 1];
+
+ if( !count($context) || (is_object($context[0]) && $context[0]->multiMedia) ){
+ $mediaNode->rules[0]->root = true;
+ }
+ }
+
+}
+