ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
Whoops\Handler\PlainTextHandler Class Reference

Handler outputing plaintext error messages. More...

+ Inheritance diagram for Whoops\Handler\PlainTextHandler:
+ Collaboration diagram for Whoops\Handler\PlainTextHandler:

Public Member Functions

 __construct ($logger=null)
 Constructor. More...
 
 setLogger ($logger=null)
 Set the output logger interface. More...
 
 getLogger ()
 
 addTraceToOutput ($addTraceToOutput=null)
 Add error trace to output. More...
 
 addTraceFunctionArgsToOutput ($addTraceFunctionArgsToOutput=null)
 Add error trace function arguments to output. More...
 
 setTraceFunctionArgsOutputLimit ($traceFunctionArgsOutputLimit)
 
 getTraceFunctionArgsOutputLimit ()
 Get the size limit in bytes of frame arguments var_dump output. More...
 
 onlyForCommandLine ($onlyForCommandLine=null)
 Restrict error handling to command line calls. More...
 
 outputOnlyIfCommandLine ($outputOnlyIfCommandLine=null)
 Output the error message only if using command line. More...
 
 loggerOnly ($loggerOnly=null)
 Only output to logger. More...
 
 handle ()
 
- Public Member Functions inherited from Whoops\Handler\Handler
 setRun (Run $run)
 
 setInspector (Inspector $inspector)
 
 setException (Exception $exception)
 

Data Fields

const VAR_DUMP_PREFIX = ' | '
 
- Data Fields inherited from Whoops\Handler\Handler
const DONE = 0x10
 Return constants that can be returned from Handler::handle to message the handler walker. More...
 
const LAST_HANDLER = 0x20
 
const QUIT = 0x30
 

Protected Attributes

 $logger
 

Private Member Functions

 isCommandLine ()
 Check, if possible, that this execution was triggered by a command line. More...
 
 canProcess ()
 Test if handler can process the exception. More...
 
 canOutput ()
 Test if handler can output to stdout. More...
 
 getFrameArgsOutput (Frame $frame, $line)
 Get the frame args var_dump. More...
 

Private Attributes

 $addTraceToOutput = true
 
 $addTraceFunctionArgsToOutput = false
 
 $traceFunctionArgsOutputLimit = 1024
 
 $onlyForCommandLine = false
 
 $outputOnlyIfCommandLine = true
 
 $loggerOnly = false
 

Additional Inherited Members

- Protected Member Functions inherited from Whoops\Handler\Handler
 getRun ()
 
 getInspector ()
 
 getException ()
 

Detailed Description

Handler outputing plaintext error messages.

Can be used directly, or will be instantiated automagically by Whoops if passed to Run::pushHandler

Definition at line 20 of file PlainTextHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Whoops\Handler\PlainTextHandler::__construct (   $logger = null)

Constructor.

Exceptions
InvalidArgumentExceptionIf argument is not null or a LoggerInterface
Parameters
\Psr\Log\LoggerInterface | null$logger

Definition at line 64 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$logger, and Whoops\Handler\PlainTextHandler\setLogger().

65  {
66  $this->setLogger($logger);
67  }
setLogger($logger=null)
Set the output logger interface.
+ Here is the call graph for this function:

Member Function Documentation

◆ addTraceFunctionArgsToOutput()

Whoops\Handler\PlainTextHandler::addTraceFunctionArgsToOutput (   $addTraceFunctionArgsToOutput = null)

Add error trace function arguments to output.

Set to True for all frame args, or integer for the n first frame args.

Parameters
bool | integer | null$addTraceFunctionArgsToOutput
Returns
null|bool|integer

Definition at line 117 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$addTraceFunctionArgsToOutput.

Referenced by Whoops\Handler\PlainTextHandler\getFrameArgsOutput().

118  {
119  if (func_num_args() == 0) {
121  }
122 
123  if (! is_integer($addTraceFunctionArgsToOutput)) {
125  } else {
127  }
128  }
addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput=null)
Add error trace function arguments to output.
+ Here is the caller graph for this function:

◆ addTraceToOutput()

Whoops\Handler\PlainTextHandler::addTraceToOutput (   $addTraceToOutput = null)

Add error trace to output.

Parameters
bool | null$addTraceToOutput
Returns
bool|$this

Definition at line 101 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$addTraceToOutput.

Referenced by Whoops\Handler\PlainTextHandler\getFrameArgsOutput().

102  {
103  if (func_num_args() == 0) {
105  }
106 
107  $this->addTraceToOutput = (bool) $addTraceToOutput;
108  return $this;
109  }
addTraceToOutput($addTraceToOutput=null)
Add error trace to output.
+ Here is the caller graph for this function:

◆ canOutput()

Whoops\Handler\PlainTextHandler::canOutput ( )
private

Test if handler can output to stdout.

Returns
bool

Definition at line 216 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\isCommandLine(), Whoops\Handler\PlainTextHandler\loggerOnly(), and Whoops\Handler\PlainTextHandler\outputOnlyIfCommandLine().

Referenced by Whoops\Handler\PlainTextHandler\handle().

217  {
218  return ($this->isCommandLine() || ! $this->outputOnlyIfCommandLine())
219  && ! $this->loggerOnly();
220  }
isCommandLine()
Check, if possible, that this execution was triggered by a command line.
loggerOnly($loggerOnly=null)
Only output to logger.
outputOnlyIfCommandLine($outputOnlyIfCommandLine=null)
Output the error message only if using command line.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canProcess()

Whoops\Handler\PlainTextHandler::canProcess ( )
private

Test if handler can process the exception.

Returns
bool

Definition at line 207 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\isCommandLine(), and Whoops\Handler\PlainTextHandler\onlyForCommandLine().

Referenced by Whoops\Handler\PlainTextHandler\handle().

208  {
209  return $this->isCommandLine() || !$this->onlyForCommandLine();
210  }
onlyForCommandLine($onlyForCommandLine=null)
Restrict error handling to command line calls.
isCommandLine()
Check, if possible, that this execution was triggered by a command line.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFrameArgsOutput()

Whoops\Handler\PlainTextHandler::getFrameArgsOutput ( Frame  $frame,
  $line 
)
private

Get the frame args var_dump.

Parameters
\Whoops\Exception\Frame$frame[description]
integer$line[description]
Returns
string

Definition at line 228 of file PlainTextHandler.php.

References Whoops\Handler\Handler\$inspector, Whoops\Handler\PlainTextHandler\addTraceFunctionArgsToOutput(), Whoops\Handler\PlainTextHandler\addTraceToOutput(), Whoops\Exception\Frame\getArgs(), Whoops\Handler\Handler\getInspector(), and Whoops\Handler\PlainTextHandler\getTraceFunctionArgsOutputLimit().

229  {
230  if ($this->addTraceFunctionArgsToOutput() === false
231  || $this->addTraceFunctionArgsToOutput() < $line) {
232  return '';
233  }
234 
235  // Dump the arguments:
236  ob_start();
237  var_dump($frame->getArgs());
238  if (ob_get_length() > $this->getTraceFunctionArgsOutputLimit()) {
239  // The argument var_dump is to big.
240  // Discarded to limit memory usage.
241  ob_clean();
242  return sprintf(
243  "\n%sArguments dump length greater than %d Bytes. Discarded.",
244  self::VAR_DUMP_PREFIX,
246  );
247  }
248 
249  return sprintf("\n%s",
250  preg_replace('/^/m', self::VAR_DUMP_PREFIX, ob_get_clean())
251  );
252  }
getTraceFunctionArgsOutputLimit()
Get the size limit in bytes of frame arguments var_dump output.
addTraceFunctionArgsToOutput($addTraceFunctionArgsToOutput=null)
Add error trace function arguments to output.
+ Here is the call graph for this function:

◆ getLogger()

Whoops\Handler\PlainTextHandler::getLogger ( )
Returns
|null

Definition at line 91 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$logger.

Referenced by Whoops\Handler\PlainTextHandler\handle().

+ Here is the caller graph for this function:

◆ getTraceFunctionArgsOutputLimit()

Whoops\Handler\PlainTextHandler::getTraceFunctionArgsOutputLimit ( )

Get the size limit in bytes of frame arguments var_dump output.

If the limit is reached, the var_dump output is discarded. Prevent memory limit errors.

Returns
integer

Definition at line 147 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$traceFunctionArgsOutputLimit.

Referenced by Whoops\Handler\PlainTextHandler\getFrameArgsOutput().

+ Here is the caller graph for this function:

◆ handle()

Whoops\Handler\PlainTextHandler::handle ( )
Returns
int

Implements Whoops\Handler\HandlerInterface.

Definition at line 298 of file PlainTextHandler.php.

References Whoops\Handler\Handler\$exception, Whoops\Handler\PlainTextHandler\canOutput(), Whoops\Handler\PlainTextHandler\canProcess(), Whoops\Util\Misc\canSendHeaders(), Whoops\Handler\Handler\DONE, Whoops\Handler\Handler\getException(), Whoops\Handler\PlainTextHandler\getLogger(), and Whoops\Handler\Handler\QUIT.

299  {
300  if (! $this->canProcess()) {
301  return Handler::DONE;
302  }
303 
304  $exception = $this->getException();
305 
306  $response = sprintf("%s: %s in file %s on line %d%s\n",
307  get_class($exception),
308  $exception->getMessage(),
309  $exception->getFile(),
310  $exception->getLine(),
311  $this->getTraceOutput()
312  );
313 
314  if ($this->getLogger()) {
315  $this->getLogger()->error($response);
316  }
317 
318  if (! $this->canOutput()) {
319  return Handler::DONE;
320  }
321 
322  if (class_exists('\Whoops\Util\Misc')
323  && \Whoops\Util\Misc::canSendHeaders()) {
324  header('Content-Type: text/plain');
325  }
326 
327  echo $response;
328 
329  return Handler::QUIT;
330  }
canProcess()
Test if handler can process the exception.
const DONE
Return constants that can be returned from Handler::handle to message the handler walker...
Definition: Handler.php:22
Whoops - php errors for cool kids.
static canSendHeaders()
Can we at this point in time send HTTP headers?
Definition: Misc.php:21
canOutput()
Test if handler can output to stdout.
+ Here is the call graph for this function:

◆ isCommandLine()

Whoops\Handler\PlainTextHandler::isCommandLine ( )
private

Check, if possible, that this execution was triggered by a command line.

Returns
bool

Definition at line 198 of file PlainTextHandler.php.

Referenced by Whoops\Handler\PlainTextHandler\canOutput(), and Whoops\Handler\PlainTextHandler\canProcess().

199  {
200  return PHP_SAPI == 'cli';
201  }
+ Here is the caller graph for this function:

◆ loggerOnly()

Whoops\Handler\PlainTextHandler::loggerOnly (   $loggerOnly = null)

Only output to logger.

Parameters
bool | null$loggerOnly
Returns
null|bool

Definition at line 185 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$loggerOnly.

Referenced by Whoops\Handler\PlainTextHandler\canOutput().

186  {
187  if (func_num_args() == 0) {
188  return $this->loggerOnly;
189  }
190 
191  $this->loggerOnly = (bool) $loggerOnly;
192  }
loggerOnly($loggerOnly=null)
Only output to logger.
+ Here is the caller graph for this function:

◆ onlyForCommandLine()

Whoops\Handler\PlainTextHandler::onlyForCommandLine (   $onlyForCommandLine = null)

Restrict error handling to command line calls.

Parameters
bool | null$onlyForCommandLine
Returns
null|bool

Definition at line 157 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$onlyForCommandLine.

Referenced by Whoops\Handler\PlainTextHandler\canProcess().

158  {
159  if (func_num_args() == 0) {
161  }
162  $this->onlyForCommandLine = (bool) $onlyForCommandLine;
163  }
onlyForCommandLine($onlyForCommandLine=null)
Restrict error handling to command line calls.
+ Here is the caller graph for this function:

◆ outputOnlyIfCommandLine()

Whoops\Handler\PlainTextHandler::outputOnlyIfCommandLine (   $outputOnlyIfCommandLine = null)

Output the error message only if using command line.

else, output to logger if available. Allow to safely add this handler to web pages.

Parameters
bool | null$outputOnlyIfCommandLine
Returns
null|bool

Definition at line 172 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$outputOnlyIfCommandLine.

Referenced by Whoops\Handler\PlainTextHandler\canOutput().

173  {
174  if (func_num_args() == 0) {
176  }
178  }
outputOnlyIfCommandLine($outputOnlyIfCommandLine=null)
Output the error message only if using command line.
+ Here is the caller graph for this function:

◆ setLogger()

Whoops\Handler\PlainTextHandler::setLogger (   $logger = null)

Set the output logger interface.

Exceptions
InvalidArgumentExceptionIf argument is not null or a LoggerInterface
Parameters
\Psr\Log\LoggerInterface | null$logger

Definition at line 74 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$logger.

Referenced by Whoops\Handler\PlainTextHandler\__construct().

75  {
76  if (! (is_null($logger)
77  || $logger instanceof LoggerInterface)) {
78  throw new InvalidArgumentException(
79  'Argument to ' . __METHOD__ .
80  " must be a valid Logger Interface (aka. Monolog), " .
81  get_class($logger) . ' given.'
82  );
83  }
84 
85  $this->logger = $logger;
86  }
+ Here is the caller graph for this function:

◆ setTraceFunctionArgsOutputLimit()

Whoops\Handler\PlainTextHandler::setTraceFunctionArgsOutputLimit (   $traceFunctionArgsOutputLimit)

Definition at line 136 of file PlainTextHandler.php.

References Whoops\Handler\PlainTextHandler\$traceFunctionArgsOutputLimit.

137  {
138  $this->traceFunctionArgsOutputLimit = (integer) $traceFunctionArgsOutputLimit;
139  }

Field Documentation

◆ $addTraceFunctionArgsToOutput

Whoops\Handler\PlainTextHandler::$addTraceFunctionArgsToOutput = false
private

◆ $addTraceToOutput

Whoops\Handler\PlainTextHandler::$addTraceToOutput = true
private

◆ $logger

Whoops\Handler\PlainTextHandler::$logger
protected

◆ $loggerOnly

Whoops\Handler\PlainTextHandler::$loggerOnly = false
private

Definition at line 57 of file PlainTextHandler.php.

Referenced by Whoops\Handler\PlainTextHandler\loggerOnly().

◆ $onlyForCommandLine

Whoops\Handler\PlainTextHandler::$onlyForCommandLine = false
private

◆ $outputOnlyIfCommandLine

Whoops\Handler\PlainTextHandler::$outputOnlyIfCommandLine = true
private

◆ $traceFunctionArgsOutputLimit

Whoops\Handler\PlainTextHandler::$traceFunctionArgsOutputLimit = 1024
private

◆ VAR_DUMP_PREFIX

const Whoops\Handler\PlainTextHandler::VAR_DUMP_PREFIX = ' | '

Definition at line 22 of file PlainTextHandler.php.


The documentation for this class was generated from the following file: