Skip to content

Commit e8b78fe

Browse files
committed
Add Core\Debug\Backtrace
Put Backtrace on index
1 parent 6675683 commit e8b78fe

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

core/debug/backtrace.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
namespace Core\Debug;
3+
4+
class Backtrace {
5+
public $trace;
6+
public function form_exception($e) {
7+
$this->trace = $e->getTrace();
8+
}
9+
10+
public function __toString() {
11+
$string = '<h1>Backtrace</h1>';
12+
foreach ($this->trace as $key => $trace) {
13+
$string.='<details>';
14+
$string.='<summary>' . $trace['file'] . ':' . $trace['line'] . '</summary>';
15+
$string.= '<pre>';
16+
$string.= print_r($trace, TRUE);
17+
$string.= '</pre>';
18+
$string.='</details>';
19+
}
20+
21+
return $string;
22+
}
23+
}

index.php

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_once('core/Parser.php');
1010
require_once('core/loader.php');
1111
require_once('core/input.php');
12+
require_once('core/debug/backtrace.php');
1213
use \Core\Parser as Parser;
1314

1415

@@ -26,4 +27,7 @@
2627
Parser::execute(Parser::controller($controller), $method, $params);
2728
} catch (Exception $e) {
2829
echo $e->message;
30+
$backtrace = new Core\Debug\Backtrace();
31+
$backtrace->form_exception($e);
32+
echo $backtrace;
2933
}

tests/Test.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require_once('core/loader.php');
1111
require_once('core/Input.php');
1212
require_once('core/views/template.php');
13+
require_once('core/debug/backtrace.php');
1314

1415
define('ENVIRONMENT', 'test');
1516
define('ENVIRONMENT_CONTROLLERS', 'tests/controllers/');

tests/backtrace.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
use Core\Debug\Backtrace as Backtrace;
3+
4+
class BacktraceTest extends PHPUnit_Framework_TestCase {
5+
function test_parse_backtrace() {
6+
try {
7+
throw new Exception();
8+
} catch (Exception $e) {
9+
$backtrace = new Backtrace();
10+
$trace = $backtrace->form_exception($e);
11+
$this->assertSame($backtrace->trace, $e->getTrace());
12+
}
13+
}
14+
15+
function test_to_string() {
16+
try {
17+
throw new Exception();
18+
} catch (Exception $e) {
19+
$backtrace = new Backtrace();
20+
$backtrace->form_exception($e);
21+
$string = $backtrace;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)