1 | <?php |
||
20 | class PlainTextHandler extends Handler |
||
21 | { |
||
22 | const VAR_DUMP_PREFIX = ' | '; |
||
23 | |||
24 | /** |
||
25 | * @var \Psr\Log\LoggerInterface |
||
26 | */ |
||
27 | protected $logger; |
||
28 | |||
29 | /** |
||
30 | * @var callable |
||
31 | */ |
||
32 | protected $dumper; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $addTraceToOutput = true; |
||
38 | |||
39 | /** |
||
40 | * @var bool|integer |
||
41 | */ |
||
42 | private $addTraceFunctionArgsToOutput = false; |
||
43 | |||
44 | /** |
||
45 | * @var integer |
||
46 | */ |
||
47 | private $traceFunctionArgsOutputLimit = 1024; |
||
48 | |||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | private $addPreviousToOutput = true; |
||
53 | |||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | private $loggerOnly = false; |
||
58 | |||
59 | /** |
||
60 | * Constructor. |
||
61 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
62 | * @param \Psr\Log\LoggerInterface|null $logger |
||
63 | */ |
||
64 | 3 | public function __construct($logger = null) |
|
68 | |||
69 | /** |
||
70 | * Set the output logger interface. |
||
71 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
72 | * @param \Psr\Log\LoggerInterface|null $logger |
||
73 | */ |
||
74 | 4 | public function setLogger($logger = null) |
|
87 | |||
88 | /** |
||
89 | * @return \Psr\Log\LoggerInterface|null |
||
90 | */ |
||
91 | 2 | public function getLogger() |
|
95 | |||
96 | /** |
||
97 | * Set var dumper callback function. |
||
98 | * |
||
99 | * @param callable $dumper |
||
100 | * @return void |
||
101 | */ |
||
102 | public function setDumper(callable $dumper) |
||
106 | |||
107 | /** |
||
108 | * Add error trace to output. |
||
109 | * @param bool|null $addTraceToOutput |
||
110 | * @return bool|$this |
||
111 | */ |
||
112 | 6 | public function addTraceToOutput($addTraceToOutput = null) |
|
121 | |||
122 | /** |
||
123 | * Add previous exceptions to output. |
||
124 | * @param bool|null $addPreviousToOutput |
||
125 | * @return bool|$this |
||
126 | */ |
||
127 | 2 | public function addPreviousToOutput($addPreviousToOutput = null) |
|
136 | |||
137 | /** |
||
138 | * Add error trace function arguments to output. |
||
139 | * Set to True for all frame args, or integer for the n first frame args. |
||
140 | * @param bool|integer|null $addTraceFunctionArgsToOutput |
||
141 | * @return null|bool|integer |
||
142 | */ |
||
143 | 4 | public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null) |
|
155 | |||
156 | /** |
||
157 | * Set the size limit in bytes of frame arguments var_dump output. |
||
158 | * If the limit is reached, the var_dump output is discarded. |
||
159 | * Prevent memory limit errors. |
||
160 | * @var integer |
||
161 | */ |
||
162 | 3 | public function setTraceFunctionArgsOutputLimit($traceFunctionArgsOutputLimit) |
|
166 | |||
167 | /** |
||
168 | * Create plain text response and return it as a string |
||
169 | * @return string |
||
170 | */ |
||
171 | 2 | public function generateResponse() |
|
187 | |||
188 | /** |
||
189 | * Get the size limit in bytes of frame arguments var_dump output. |
||
190 | * If the limit is reached, the var_dump output is discarded. |
||
191 | * Prevent memory limit errors. |
||
192 | * @return integer |
||
193 | */ |
||
194 | 1 | public function getTraceFunctionArgsOutputLimit() |
|
198 | |||
199 | /** |
||
200 | * Only output to logger. |
||
201 | * @param bool|null $loggerOnly |
||
202 | * @return null|bool |
||
203 | */ |
||
204 | 3 | public function loggerOnly($loggerOnly = null) |
|
212 | |||
213 | /** |
||
214 | * Test if handler can output to stdout. |
||
215 | * @return bool |
||
216 | */ |
||
217 | 4 | private function canOutput() |
|
221 | |||
222 | /** |
||
223 | * Get the frame args var_dump. |
||
224 | * @param \Whoops\Exception\Frame $frame [description] |
||
225 | * @param integer $line [description] |
||
226 | * @return string |
||
227 | */ |
||
228 | 1 | private function getFrameArgsOutput(Frame $frame, $line) |
|
254 | |||
255 | /** |
||
256 | * Dump variable. |
||
257 | * |
||
258 | * @param mixed $var |
||
259 | * @return void |
||
260 | */ |
||
261 | protected function dump($var) |
||
269 | |||
270 | /** |
||
271 | * Get the exception trace as plain text. |
||
272 | * @return string |
||
273 | */ |
||
274 | 4 | private function getTraceOutput() |
|
310 | |||
311 | /** |
||
312 | * Get the exception as plain text. |
||
313 | * @param \Throwable $exception |
||
314 | * @return string |
||
315 | */ |
||
316 | 2 | private function getExceptionOutput($exception) |
|
326 | |||
327 | /** |
||
328 | * @return int |
||
329 | */ |
||
330 | 5 | public function handle() |
|
346 | |||
347 | /** |
||
348 | * @return string |
||
349 | */ |
||
350 | 2 | public function contentType() |
|
354 | } |
||
355 |