/** * Visit an element. * * @param \Hoa\Visitor\Element $element Element to visit. * @param mixed &$handle Handle (reference). * @param mixed $eldnah Handle (not reference). * @return string */ public function visit(Visitor\Element $element, &$handle = null, $eldnah = null) { $pre = null; $in = '> ' . str_repeat(' ', $this->_i) . $element->getValue() . "\n"; $post = null; $childs = $element->getChilds(); $i = 0; $max = floor(count($childs) / 2); ++$this->_i; foreach ($childs as $id => $child) { if ($i++ < $max) { $pre .= $child->accept($this, $handle, $eldnah); } else { $post .= $child->accept($this, $handle, $eldnah); } } --$this->_i; switch ($this->getOrder()) { case parent::IN_ORDER: return $in . $pre . $post; case parent::POST_ORDER: return $post . $in . $pre; default: return $pre . $in . $post; } }
/** * Visit an element. * * @param \Hoa\Visitor\Element $element Element to visit. * @param mixed &$handle Handle (reference). * @param mixed $eldnah Handle (not reference). * @return string */ public function visit(Visitor\Element $element, &$handle = null, $eldnah = null) { $ou = null; $t = null; if ($this->_i == 0) { $ou = 'digraph {' . "\n"; $t = '}' . "\n"; } $foo = $element->getValue(); $bar = null; ++$this->_i; if (null == $eldnah) { $eldnah = $foo; $ou .= ' "' . md5($foo) . '" [label = "' . $foo . '"];' . "\n"; } foreach ($element->getChilds() as $child) { $left = md5($eldnah); $right = md5($eldnah . '.' . $child->getValue()); $ou .= ' "' . $left . '" -> "' . $right . '";' . "\n" . ' "' . $right . '" [label = "' . str_replace('\\', '\\\\', $child->getValue()) . '"];' . "\n"; $bar .= $child->accept($this, $handle, $eldnah . '.' . $child->getValue()); } $ou .= $bar; --$this->_i; return $ou . $t; }