File tree 4 files changed +52
-0
lines changed
4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 9
9
require_once ('core/Parser.php ' );
10
10
require_once ('core/loader.php ' );
11
11
require_once ('core/input.php ' );
12
+ require_once ('core/debug/backtrace.php ' );
12
13
use \Core \Parser as Parser ;
13
14
14
15
26
27
Parser::execute (Parser::controller ($ controller ), $ method , $ params );
27
28
} catch (Exception $ e ) {
28
29
echo $ e ->message ;
30
+ $ backtrace = new Core \Debug \Backtrace ();
31
+ $ backtrace ->form_exception ($ e );
32
+ echo $ backtrace ;
29
33
}
Original file line number Diff line number Diff line change 10
10
require_once ('core/loader.php ' );
11
11
require_once ('core/Input.php ' );
12
12
require_once ('core/views/template.php ' );
13
+ require_once ('core/debug/backtrace.php ' );
13
14
14
15
define ('ENVIRONMENT ' , 'test ' );
15
16
define ('ENVIRONMENT_CONTROLLERS ' , 'tests/controllers/ ' );
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments