Hoa central
Dump.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Tree\Visitor;
38 
39 use Hoa\Visitor;
40 
49 class Dump extends Generic implements Visitor\Visit
50 {
56  protected $_i = 0;
57 
58 
59 
67  public function __construct($order = parent::IN_ORDER)
68  {
69  parent::__construct($order);
70 
71  return;
72  }
73 
82  public function visit(
83  Visitor\Element $element,
84  &$handle = null,
85  $eldnah = null
86  ) {
87  $pre = null;
88  $in = '> ' . str_repeat(' ', $this->_i) . $element->getValue() . "\n";
89  $post = null;
90  $childs = $element->getChilds();
91  $i = 0;
92  $max = floor(count($childs) / 2);
93 
94  ++$this->_i;
95 
96  foreach ($childs as $id => $child) {
97  if ($i++ < $max) {
98  $pre .= $child->accept($this, $handle, $eldnah);
99  } else {
100  $post .= $child->accept($this, $handle, $eldnah);
101  }
102  }
103 
104  --$this->_i;
105 
106  switch ($this->getOrder()) {
107  case parent::IN_ORDER:
108  return $in . $pre . $post;
109 
110  case parent::POST_ORDER:
111  return $post . $in . $pre;
112 
113  default:
114  return $pre . $in . $post;
115  }
116  }
117 }
__construct($order=parent::IN_ORDER)
Definition: Dump.php:67
visit(Visitor\Element $element, &$handle=null, $eldnah=null)
Definition: Dump.php:82