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