Hoa central
Dot.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Tree\Visitor;
38 
39 use Hoa\Visitor;
40 
49 class Dot extends Generic implements Visitor\Visit
50 {
56  protected $_i = 0;
57 
58 
59 
68  public function visit(
69  Visitor\Element $element,
70  &$handle = null,
71  $eldnah = null
72  ) {
73  $ou = null;
74  $t = null;
75 
76  if ($this->_i == 0) {
77  $ou = 'digraph {' . "\n";
78  $t = '}' . "\n";
79  }
80 
81  $foo = $element->getValue();
82  $bar = null;
83  ++$this->_i;
84 
85  if (null == $eldnah) {
86  $eldnah = $foo;
87  $ou .= ' "' . md5($foo) . '" [label = "' . $foo . '"];' . "\n";
88  }
89 
90  foreach ($element->getChilds() as $child) {
91  $left = md5($eldnah);
92  $right = md5($eldnah . '.' . $child->getValue());
93 
94  $ou .=
95  ' "' . $left . '" -> "' . $right . '";' . "\n" .
96  ' "' . $right . '" [label = "' .
97  str_replace('\\', '\\\\', $child->getValue()) .
98  '"];' . "\n";
99  $bar .=
100  $child->accept($this, $handle, $eldnah . '.' .
101  $child->getValue());
102  }
103 
104  $ou .= $bar;
105 
106  --$this->_i;
107 
108  return $ou . $t;
109  }
110 }
visit(Visitor\Element $element, &$handle=null, $eldnah=null)
Definition: Dot.php:68