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 $loggerOnly = false; |
||
53 | |||
54 | /** |
||
55 | * Constructor. |
||
56 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
57 | * @param \Psr\Log\LoggerInterface|null $logger |
||
58 | */ |
||
59 | 1 | public function __construct($logger = null) |
|
63 | |||
64 | /** |
||
65 | * Set the output logger interface. |
||
66 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
67 | * @param \Psr\Log\LoggerInterface|null $logger |
||
68 | */ |
||
69 | 2 | public function setLogger($logger = null) |
|
82 | |||
83 | /** |
||
84 | * @return \Psr\Log\LoggerInterface|null |
||
85 | */ |
||
86 | public function getLogger() |
||
90 | |||
91 | /** |
||
92 | * Set var dumper callback function. |
||
93 | * |
||
94 | * @param callable $dumper |
||
95 | * @return void |
||
96 | */ |
||
97 | public function setDumper(callable $dumper) |
||
101 | |||
102 | /** |
||
103 | * Add error trace to output. |
||
104 | * @param bool|null $addTraceToOutput |
||
105 | * @return bool|$this |
||
106 | */ |
||
107 | 4 | public function addTraceToOutput($addTraceToOutput = null) |
|
116 | |||
117 | /** |
||
118 | * Add error trace function arguments to output. |
||
119 | * Set to True for all frame args, or integer for the n first frame args. |
||
120 | * @param bool|integer|null $addTraceFunctionArgsToOutput |
||
121 | * @return null|bool|integer |
||
122 | */ |
||
123 | 2 | public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null) |
|
135 | |||
136 | /** |
||
137 | * Set the size limit in bytes of frame arguments var_dump output. |
||
138 | * If the limit is reached, the var_dump output is discarded. |
||
139 | * Prevent memory limit errors. |
||
140 | * @var integer |
||
141 | */ |
||
142 | 1 | public function setTraceFunctionArgsOutputLimit($traceFunctionArgsOutputLimit) |
|
146 | |||
147 | /** |
||
148 | * Create plain text response and return it as a string |
||
149 | * @return string |
||
150 | */ |
||
151 | public function generateResponse() |
||
162 | |||
163 | /** |
||
164 | * Get the size limit in bytes of frame arguments var_dump output. |
||
165 | * If the limit is reached, the var_dump output is discarded. |
||
166 | * Prevent memory limit errors. |
||
167 | * @return integer |
||
168 | */ |
||
169 | 1 | public function getTraceFunctionArgsOutputLimit() |
|
173 | |||
174 | /** |
||
175 | * Only output to logger. |
||
176 | * @param bool|null $loggerOnly |
||
177 | * @return null|bool |
||
178 | */ |
||
179 | 1 | public function loggerOnly($loggerOnly = null) |
|
187 | |||
188 | /** |
||
189 | * Test if handler can output to stdout. |
||
190 | * @return bool |
||
191 | */ |
||
192 | 2 | private function canOutput() |
|
196 | |||
197 | /** |
||
198 | * Get the frame args var_dump. |
||
199 | * @param \Whoops\Exception\Frame $frame [description] |
||
200 | * @param integer $line [description] |
||
201 | * @return string |
||
202 | */ |
||
203 | 1 | private function getFrameArgsOutput(Frame $frame, $line) |
|
228 | |||
229 | /** |
||
230 | * Dump variable. |
||
231 | * |
||
232 | * @param mixed $var |
||
233 | * @return void |
||
234 | */ |
||
235 | protected function dump($var) |
||
243 | |||
244 | /** |
||
245 | * Get the exception trace as plain text. |
||
246 | * @return string |
||
247 | */ |
||
248 | 2 | private function getTraceOutput() |
|
284 | |||
285 | /** |
||
286 | * @return int |
||
287 | */ |
||
288 | 3 | public function handle() |
|
304 | |||
305 | /** |
||
306 | * @return string |
||
307 | */ |
||
308 | public function contentType() |
||
312 | } |
||
313 |