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 static |
||
101 | */ |
||
102 | public function setDumper(callable $dumper) |
||
107 | |||
108 | /** |
||
109 | * Add error trace to output. |
||
110 | * @param bool|null $addTraceToOutput |
||
111 | * @return bool|static |
||
112 | */ |
||
113 | 6 | public function addTraceToOutput($addTraceToOutput = null) |
|
122 | |||
123 | /** |
||
124 | * Add previous exceptions to output. |
||
125 | * @param bool|null $addPreviousToOutput |
||
126 | * @return bool|static |
||
127 | */ |
||
128 | 2 | public function addPreviousToOutput($addPreviousToOutput = null) |
|
137 | |||
138 | /** |
||
139 | * Add error trace function arguments to output. |
||
140 | * Set to True for all frame args, or integer for the n first frame args. |
||
141 | * @param bool|integer|null $addTraceFunctionArgsToOutput |
||
142 | * @return static|bool|integer |
||
143 | */ |
||
144 | 4 | public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null) |
|
157 | |||
158 | /** |
||
159 | * Set the size limit in bytes of frame arguments var_dump output. |
||
160 | * If the limit is reached, the var_dump output is discarded. |
||
161 | * Prevent memory limit errors. |
||
162 | * @var integer |
||
163 | * @return static |
||
164 | */ |
||
165 | 3 | public function setTraceFunctionArgsOutputLimit($traceFunctionArgsOutputLimit) |
|
170 | |||
171 | /** |
||
172 | * Create plain text response and return it as a string |
||
173 | * @return string |
||
174 | */ |
||
175 | 2 | public function generateResponse() |
|
191 | |||
192 | /** |
||
193 | * Get the size limit in bytes of frame arguments var_dump output. |
||
194 | * If the limit is reached, the var_dump output is discarded. |
||
195 | * Prevent memory limit errors. |
||
196 | * @return integer |
||
197 | */ |
||
198 | 1 | public function getTraceFunctionArgsOutputLimit() |
|
202 | |||
203 | /** |
||
204 | * Only output to logger. |
||
205 | * @param bool|null $loggerOnly |
||
206 | * @return static|bool |
||
207 | */ |
||
208 | 3 | public function loggerOnly($loggerOnly = null) |
|
217 | |||
218 | /** |
||
219 | * Test if handler can output to stdout. |
||
220 | * @return bool |
||
221 | */ |
||
222 | 4 | private function canOutput() |
|
226 | |||
227 | /** |
||
228 | * Get the frame args var_dump. |
||
229 | * @param \Whoops\Exception\Frame $frame [description] |
||
230 | * @param integer $line [description] |
||
231 | * @return string |
||
232 | */ |
||
233 | 1 | private function getFrameArgsOutput(Frame $frame, $line) |
|
259 | |||
260 | /** |
||
261 | * Dump variable. |
||
262 | * |
||
263 | * @param mixed $var |
||
264 | * @return void |
||
265 | */ |
||
266 | protected function dump($var) |
||
274 | |||
275 | /** |
||
276 | * Get the exception trace as plain text. |
||
277 | * @return string |
||
278 | */ |
||
279 | 4 | private function getTraceOutput() |
|
315 | |||
316 | /** |
||
317 | * Get the exception as plain text. |
||
318 | * @param \Throwable $exception |
||
319 | * @return string |
||
320 | */ |
||
321 | 2 | private function getExceptionOutput($exception) |
|
331 | |||
332 | /** |
||
333 | * @return int |
||
334 | */ |
||
335 | 5 | public function handle() |
|
351 | |||
352 | /** |
||
353 | * @return string |
||
354 | */ |
||
355 | 2 | public function contentType() |
|
359 | } |
||
360 |