本文整理汇总了PHP中Throwable::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::__toString方法的具体用法?PHP Throwable::__toString怎么用?PHP Throwable::__toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Throwable
的用法示例。
在下文中一共展示了Throwable::__toString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handler
/**
* Throwable handler.
*
* @since 160711 Throwables.
*
* @param \Throwable $Throwable Error/Exception.
*/
public function handler(\Throwable $Throwable)
{
if ($this->c::isCli()) {
// Set `STDERR` so that it can be used in CLI feedback.
// If debugging, `STDERR` should include a full stack trace.
// If it's not an interactive terminal session, try to log the error.
// The exit status should always be `1` to indicate an error.
try {
// Catch throwables.
$this->c::noCacheFlags();
$this->c::sessionWriteClose();
$this->c::obEndCleanAll();
if ($this->App->Config->©debug['©enable']) {
$this->c::writeStderr($Throwable->__toString());
} else {
$this->c::writeStderr($Throwable->getMessage());
}
if (!$this->c::isCliInteractive()) {
error_log(str_replace("", '', $Throwable->__toString()));
}
exit(1);
// Exit status code.
//
} catch (\Throwable $inner_Throwable) {
// Edge case.
exit(1);
// Simply exit in this edge case.
}
} elseif (!headers_sent()) {
// Send a 500 error response code.
// If there is a throwable template, use the throwable template.
// In either case, rethrow; i.e., allow PHP to log as an error.
// It's also IMPORTANT to rethrow so that execution stops!
try {
// Catch throwables.
$this->c::noCacheFlags();
$this->c::sessionWriteClose();
$this->c::obEndCleanAll();
$this->c::statusHeader(500);
$this->c::noCacheHeaders();
header('content-type: text/html; charset=utf-8');
echo $this->c::getTemplate('http/html/status/500.php')->parse(['Throwable' => $Throwable]);
//
} catch (\Throwable $inner_Throwable) {
echo 'Unexpected error. Please try again.' . "\n";
// Edge case.
}
throw $Throwable;
// Rethrow. i.e., allow PHP to log as an error.
// ↑ NOTE: Assumes throwables will not be handled here when `display_errors=yes`.
// Therefore, when the above template is displayed, that's all you'll see in most cases.
// i.e., Under most conditions, the display of this PHP error should not be seen. Only logged.
} else {
// Should be avoided. It's always better to buffer output so that an error
// can be shown instead of what would have been output to a browser otherwise.
// Our own template handler uses output buffering so this is not an issue with core.
throw $Throwable;
// Rethrow. i.e., log and/or display if debugging.
}
}
示例2: onAppError
private function onAppError($clientId, \Throwable $e) : \Generator
{
$this->logger->error($e->__toString());
$code = Code::UNEXPECTED_SERVER_ERROR;
$reason = "Internal server error, aborting";
yield from $this->doClose($this->clients[$clientId], $code, $reason);
}
示例3: onAppError
private function onAppError($clientId, \Throwable $e) : \Generator
{
$this->logger->error($e->__toString());
$code = Code::UNEXPECTED_SERVER_ERROR;
$reason = "Internal server error, aborting";
if (isset($this->clients[$clientId])) {
// might have been already unloaded + closed
yield from $this->doClose($this->clients[$clientId], $code, $reason);
}
}
示例4: __toString
/**
* Returns a string representation of the handler
*
* @author Art <a.molcanovas@gmail.com>
* @return string
*/
public function __toString()
{
return parent::__toString() . self::EOL . 'Registered: ' . (self::$registered ? 'Yes' : 'No') . self::EOL . 'Previous exception recursion limit: ' . $this->config->prevExceptionDepth . self::EOL . 'Last reported exception: ' . (self::$lastReported ? self::$lastReported->__toString() : '[none]');
}