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 bool |
||
31 | */ |
||
32 | private $addTraceToOutput = true; |
||
33 | |||
34 | /** |
||
35 | * @var bool|integer |
||
36 | */ |
||
37 | private $addTraceFunctionArgsToOutput = false; |
||
38 | |||
39 | /** |
||
40 | * @var integer |
||
41 | */ |
||
42 | private $traceFunctionArgsOutputLimit = 1024; |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | private $loggerOnly = false; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
52 | * @param \Psr\Log\LoggerInterface|null $logger |
||
53 | */ |
||
54 | 1 | public function __construct($logger = null) |
|
55 | { |
||
56 | 1 | $this->setLogger($logger); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Set the output logger interface. |
||
61 | * @throws InvalidArgumentException If argument is not null or a LoggerInterface |
||
62 | * @param \Psr\Log\LoggerInterface|null $logger |
||
63 | */ |
||
64 | 2 | public function setLogger($logger = null) |
|
77 | |||
78 | /** |
||
79 | * @return \Psr\Log\LoggerInterface|null |
||
80 | */ |
||
81 | public function getLogger() |
||
85 | |||
86 | /** |
||
87 | * Add error trace to output. |
||
88 | * @param bool|null $addTraceToOutput |
||
89 | * @return bool|$this |
||
90 | */ |
||
91 | 4 | public function addTraceToOutput($addTraceToOutput = null) |
|
100 | |||
101 | /** |
||
102 | * Add error trace function arguments to output. |
||
103 | * Set to True for all frame args, or integer for the n first frame args. |
||
104 | * @param bool|integer|null $addTraceFunctionArgsToOutput |
||
105 | * @return null|bool|integer |
||
106 | */ |
||
107 | 2 | public function addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput = null) |
|
119 | |||
120 | /** |
||
121 | * Set the size limit in bytes of frame arguments var_dump output. |
||
122 | * If the limit is reached, the var_dump output is discarded. |
||
123 | * Prevent memory limit errors. |
||
124 | * @var integer |
||
125 | */ |
||
126 | 1 | public function setTraceFunctionArgsOutputLimit($traceFunctionArgsOutputLimit) |
|
130 | |||
131 | /** |
||
132 | * Create plain text response and return it as a string |
||
133 | * @return string |
||
134 | */ |
||
135 | public function generateResponse() |
||
146 | |||
147 | /** |
||
148 | * Get the size limit in bytes of frame arguments var_dump output. |
||
149 | * If the limit is reached, the var_dump output is discarded. |
||
150 | * Prevent memory limit errors. |
||
151 | * @return integer |
||
152 | */ |
||
153 | 1 | public function getTraceFunctionArgsOutputLimit() |
|
157 | |||
158 | /** |
||
159 | * Only output to logger. |
||
160 | * @param bool|null $loggerOnly |
||
161 | * @return null|bool |
||
162 | */ |
||
163 | 1 | public function loggerOnly($loggerOnly = null) |
|
171 | |||
172 | /** |
||
173 | * Test if handler can output to stdout. |
||
174 | * @return bool |
||
175 | */ |
||
176 | 2 | private function canOutput() |
|
180 | |||
181 | /** |
||
182 | * Get the frame args var_dump. |
||
183 | * @param \Whoops\Exception\Frame $frame [description] |
||
184 | * @param integer $line [description] |
||
185 | * @return string |
||
186 | */ |
||
187 | 1 | private function getFrameArgsOutput(Frame $frame, $line) |
|
212 | |||
213 | /** |
||
214 | * Get the exception trace as plain text. |
||
215 | * @return string |
||
216 | */ |
||
217 | 2 | private function getTraceOutput() |
|
253 | |||
254 | /** |
||
255 | * @return int |
||
256 | */ |
||
257 | 3 | public function handle() |
|
273 | |||
274 | /** |
||
275 | * @return string |
||
276 | */ |
||
277 | public function contentType() |
||
281 | } |
||
282 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: