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
|
|
|
public function addFlash($key, $content) |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
40
|
|
|
|
41
|
|
|
$btarray0 = ([ |
42
|
|
|
'class2' => $backtrace[1]['class'], |
43
|
|
|
'type2' => $backtrace[1]['type'], |
44
|
|
|
'function2' => $backtrace[1]['function'], |
45
|
|
|
'spacer4' => ' ', |
46
|
|
|
'line2' => $backtrace[0]['line'], |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$tag = implode('', $btarray0); |
50
|
|
|
|
51
|
|
|
$this->container->flash->addMessage($tag . ' ' . $key, $content); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Receives N parameters and sends them to the console adding where was it called from. |
56
|
|
|
*/ |
57
|
|
|
public function prtrace() |
58
|
|
|
{ |
59
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
60
|
|
|
|
61
|
|
|
$btarray0 = ([ |
62
|
|
|
/*'class0' => $backtrace[3]['class'], |
63
|
|
|
'type0' => $backtrace[3]['type'], |
64
|
|
|
'function0' => $backtrace[3]['function'], |
65
|
|
|
'spacer0' => ' ', |
66
|
|
|
'line0' => $backtrace[2]['line'], |
67
|
|
|
|
68
|
|
|
'spacer1' => "\n", |
69
|
|
|
|
70
|
|
|
'class1' => $backtrace[2]['class'], |
71
|
|
|
'type1' => $backtrace[2]['type'], |
72
|
|
|
'function1' => $backtrace[2]['function'], |
73
|
|
|
'spacer2' => ' ', |
74
|
|
|
'line1' => $backtrace[1]['line'], |
75
|
|
|
|
76
|
|
|
'spacer3' => "\n",*/ |
77
|
|
|
|
78
|
|
|
'class2' => $backtrace[1]['class'], |
79
|
|
|
'type2' => $backtrace[1]['type'], |
80
|
|
|
'function2' => $backtrace[1]['function'], |
81
|
|
|
'spacer4' => ' ', |
82
|
|
|
'line2' => $backtrace[0]['line'], |
83
|
|
|
]); |
84
|
|
|
|
85
|
|
|
$tag = implode('', $btarray0); |
86
|
|
|
|
87
|
|
|
\PC::debug(func_get_args(), $tag); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Receives N parameters and sends them to the console adding where was it |
92
|
|
|
* called from. |
93
|
|
|
*/ |
94
|
|
|
public static function statictrace() |
95
|
|
|
{ |
96
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
97
|
|
|
|
98
|
|
|
$btarray0 = [ |
99
|
|
|
'class' => $backtrace[1]['class'], |
100
|
|
|
'type' => $backtrace[1]['type'], |
101
|
|
|
'function' => $backtrace[1]['function'], |
102
|
|
|
'spacer' => ' ', |
103
|
|
|
'line' => $backtrace[0]['line'], |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
$tag = implode('', $btarray0); |
107
|
|
|
|
108
|
|
|
\PC::debug(func_get_args(), $tag); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns a string with html <br> variant replaced with a new line. |
113
|
|
|
* |
114
|
|
|
* @param string $msg message to parse (<br> separated) |
115
|
|
|
* |
116
|
|
|
* @return string parsed message (linebreak separated) |
117
|
|
|
*/ |
118
|
|
|
public static function br2ln($msg) |
119
|
|
|
{ |
120
|
|
|
return str_replace(['<br>', '<br/>', '<br />'], "\n", $msg); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function dump() |
124
|
|
|
{ |
125
|
|
|
call_user_func_array('\Kint::dump', func_get_args()); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function dumpAndDie() |
129
|
|
|
{ |
130
|
|
|
|
131
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
132
|
|
|
|
133
|
|
|
$folder = dirname(dirname(__DIR__)); |
134
|
|
|
$file = str_replace($folder, '', $backtrace[0]['file']); |
135
|
|
|
$line = $backtrace[0]['line']; |
136
|
|
|
|
137
|
|
|
call_user_func_array('\Kint::dump', func_get_args()); |
138
|
|
|
$this->halt('stopped by user at ' . $file . ' line ' . $line); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|