Hoa central
Backtrace.php
Go to the documentation of this file.
1 <?php
2 
37 namespace {
38 
39 from('Hoa')
40 
41 
44 -> import('Tree.~')
45 
49 -> import('Log.Backtrace.Node')
50 
54 -> import('Tree.Visitor.Dot');
55 
56 }
57 
58 namespace Hoa\Log\Backtrace {
59 
72 class Backtrace {
73 
79  protected $_tree = null;
80 
81 
82 
89  public function __construct ( ) {
90 
91  $this->_tree = new \Hoa\Tree(
92  new Node(array(
93  'function' => 'Bootstrap',
94  'line' => 42,
95  'file' => 'BigBlackHole',
96  'class' => null,
97  'object' => null,
98  'type' => null,
99  'args' => null
100  ))
101  );
102 
103  return;
104  }
105 
113  protected function computeTree ( Array $array = array() ) {
114 
115  $node = null;
116  $child = null;
117  $currentNode = $this->_tree;
118 
119  foreach($array as $i => $trace) {
120 
121  $node = new Node($trace);
122 
123  if(true === $currentNode->childExists($node->getId()))
124  $currentNode = $currentNode->getChild($node->getId());
125  else {
126 
127  $child = new \Hoa\Tree($node);
128  $currentNode->insert($child);
129  $currentNode = $child;
130  }
131  }
132 
133  return;
134  }
135 
142  public function debug ( ) {
143 
144  $array = debug_backtrace();
145  array_shift($array); // \Hoa\Log\Backtrace::debug().
146 
147  if(isset($array[0]['class']) && $array[0]['class'] == 'Hoa\Log\Log')
148  array_shift($array); // Hoa\Log::log().
149 
150  if(isset($array[0]['function']) && $array[0]['function'] == 'hlog')
151  array_shift($array); // hlog().
152 
153  $this->computeTree(array_reverse($array));
154 
155  return;
156  }
157 
164  public function getTree ( ) {
165 
166  return $this->_tree;
167  }
168 
175  public function __toString ( ) {
176 
177  $out = new \Hoa\Tree\Visitor\Dot();
178 
179  return $out->visit($this->getTree());
180  }
181 }
182 
183 }
184 
185 namespace {
186 
190 Hoa\Core\Consistency::flexEntity('Hoa\Log\Backtrace\Backtrace');
191 
192 }
computeTree(Array $array=array())
Definition: Backtrace.php:113