MDL-61015 course: consistently display hidden sections
[moodle.git] / lib / lessphp / VisitorReplacing.php
blob5923170e2fe4750939a3da22cfa6376b8a497362
1 <?php
3 /**
4 * Replacing Visitor
6 * @package Less
7 * @subpackage visitor
8 */
9 class Less_VisitorReplacing extends Less_Visitor{
11 public function visitObj( $node ){
13 $funcName = 'visit'.$node->type;
14 if( isset($this->_visitFnCache[$funcName]) ){
16 $visitDeeper = true;
17 $node = $this->$funcName( $node, $visitDeeper );
19 if( $node ){
20 if( $visitDeeper && is_object($node) ){
21 $node->accept($this);
24 $funcName = $funcName . "Out";
25 if( isset($this->_visitFnCache[$funcName]) ){
26 $this->$funcName( $node );
30 }else{
31 $node->accept($this);
34 return $node;
37 public function visitArray( $nodes ){
39 $newNodes = array();
40 foreach($nodes as $node){
41 $evald = $this->visitObj($node);
42 if( $evald ){
43 if( is_array($evald) ){
44 self::flatten($evald,$newNodes);
45 }else{
46 $newNodes[] = $evald;
50 return $newNodes;
53 public function flatten( $arr, &$out ){
55 foreach($arr as $item){
56 if( !is_array($item) ){
57 $out[] = $item;
58 continue;
61 foreach($item as $nestedItem){
62 if( is_array($nestedItem) ){
63 self::flatten( $nestedItem, $out);
64 }else{
65 $out[] = $nestedItem;
70 return $out;