1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.43 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Traits; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @file |
11
|
|
|
* A trait with helpers methods to debug, halt the app and format text to html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A trait with helpers methods to debug, halt the app and format text to html. |
16
|
|
|
* |
17
|
|
|
* @package PHPPgAdmin |
18
|
|
|
*/ |
19
|
|
|
trait HelperTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Halts the execution of the program. It's like calling exit() but using builtin Slim Exceptions. |
23
|
|
|
* |
24
|
|
|
* @param string $msg The message to show to the user |
25
|
|
|
* |
26
|
|
|
* @throws \Slim\Exception\SlimException (description) |
27
|
|
|
*/ |
28
|
|
|
public function halt($msg = 'An error has happened') |
29
|
|
|
{ |
30
|
|
|
$body = $this->container->responseobj->getBody(); |
31
|
|
|
$body->write($msg); |
32
|
|
|
|
33
|
|
|
throw new \Slim\Exception\SlimException($this->container->requestobj, $this->container->responseobj); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Receives N parameters and sends them to the console adding where was it called from. |
38
|
|
|
*/ |
39
|
|
|
public function prtrace() |
40
|
|
|
{ |
41
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
42
|
|
|
|
43
|
|
|
$btarray0 = ([ |
44
|
|
|
/*'class0' => $backtrace[3]['class'], |
45
|
|
|
'type0' => $backtrace[3]['type'], |
46
|
|
|
'function0' => $backtrace[3]['function'], |
47
|
|
|
'spacer0' => ' ', |
48
|
|
|
'line0' => $backtrace[2]['line'], |
49
|
|
|
|
50
|
|
|
'spacer1' => "\n", |
51
|
|
|
|
52
|
|
|
'class1' => $backtrace[2]['class'], |
53
|
|
|
'type1' => $backtrace[2]['type'], |
54
|
|
|
'function1' => $backtrace[2]['function'], |
55
|
|
|
'spacer2' => ' ', |
56
|
|
|
'line1' => $backtrace[1]['line'], |
57
|
|
|
|
58
|
|
|
'spacer3' => "\n",*/ |
59
|
|
|
|
60
|
|
|
'class2' => $backtrace[1]['class'], |
61
|
|
|
'type2' => $backtrace[1]['type'], |
62
|
|
|
'function2' => $backtrace[1]['function'], |
63
|
|
|
'spacer4' => ' ', |
64
|
|
|
'line2' => $backtrace[0]['line'], |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
$tag = implode('', $btarray0); |
68
|
|
|
|
69
|
|
|
\PC::debug(func_get_args(), $tag); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Receives N parameters and sends them to the console adding where was it |
74
|
|
|
* called from. |
75
|
|
|
*/ |
76
|
|
|
public static function statictrace() |
77
|
|
|
{ |
78
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
79
|
|
|
|
80
|
|
|
$btarray0 = ([ |
81
|
|
|
'class' => $backtrace[1]['class'], |
82
|
|
|
'type' => $backtrace[1]['type'], |
83
|
|
|
'function' => $backtrace[1]['function'], |
84
|
|
|
'spacer' => ' ', |
85
|
|
|
'line' => $backtrace[0]['line'], |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
$tag = implode('', $btarray0); |
89
|
|
|
|
90
|
|
|
\PC::debug(func_get_args(), $tag); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns a string with html <br> variant replaced with a new line. |
95
|
|
|
* |
96
|
|
|
* @param string $msg message to parse (<br> separated) |
97
|
|
|
* |
98
|
|
|
* @return string parsed message (linebreak separated) |
99
|
|
|
*/ |
100
|
|
|
public static function br2ln($msg) |
101
|
|
|
{ |
102
|
|
|
return str_replace(['<br>', '<br/>', '<br />'], "\n", $msg); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function dump() |
106
|
|
|
{ |
107
|
|
|
call_user_func_array('\Kint::dump', func_get_args()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function dumpAndDie() |
111
|
|
|
{ |
112
|
|
|
call_user_func_array('\Kint::dump', func_get_args()); |
113
|
|
|
$this->halt('stopped by user'); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|