本文整理汇总了PHP中Throwable::getFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::getFile方法的具体用法?PHP Throwable::getFile怎么用?PHP Throwable::getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Throwable
的用法示例。
在下文中一共展示了Throwable::getFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: error
/**
* Return an error into an HTTP or JSON data array.
*
* @param string $title
* @return array
*/
public function error($title = null)
{
if ($title == null) {
$title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
}
$type = $this->request->getHeader('Content-Type');
$mesg = $this->exception->getMessage();
$file = $this->exception->getFile();
$line = $this->exception->getLine();
$code = $this->exception->getCode();
$statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
// Check status code is null
if ($statusCode == null) {
$statusCode = $code >= 100 && $code <= 500 ? $code : 400;
}
$this->response->withStatus($statusCode);
// Check logger exist
if ($this->logger !== null) {
// Send error to log
$this->logger->addError($this->exception->getMessage());
}
$this->isJson = isset($type[0]) && $type[0] == 'application/json';
// Check content-type is application/json
if ($this->isJson) {
// Define content-type to json
$this->response->withHeader('Content-Type', 'application/json');
$error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
// Check debug
if ($this->debug) {
$error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
}
return $error;
}
// Define content-type to html
$this->response->withHeader('Content-Type', 'text/html');
$message = sprintf('<span>%s</span>', htmlentities($mesg));
$error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
// Check debug
if ($this->debug) {
$trace = $this->exception->getTraceAsString();
$trace = sprintf('<pre>%s</pre>', htmlentities($trace));
$error['file'] = $file;
$error['line'] = $line;
$error['code'] = $code;
$error['trace'] = $trace;
}
$error['debug'] = $this->debug;
$error['title'] = $title;
return $error;
}
示例2: friendlyExceptionHandler
public function friendlyExceptionHandler(\Throwable $exception)
{
$message = $exception->getMessage();
$file = $exception->getFile();
$line = $exception->getLine();
//
$obLevel = ob_get_level();
if ($obLevel > 0) {
ob_end_clean();
}
if (self::$_isActive) {
echo $message;
return;
}
self::$_isActive = true;
// Log Messages
error_log("Exception: " . $message . " in {$file} on line {$line}");
$html = '<html lang="' . $this->_htmlLang . '"><head><meta charset="UTF-8"><title>' . $this->_escapeString($message) . '</title></head><body>';
$html .= '<table width="100%" height="100%"><tr><td><table width="50%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#cccccc">';
$html .= '<tr bgcolor="#dddddd"><td height="40">' . $this->_tableTitle . '</td></tr><tr bgcolor="#ffffff"><td height="150" align="center">';
$html .= $this->_escapeString($message);
$html .= '</td></tr><tr bgcolor="#f2f2f2"><td height="40" align="center"><a href="/">' . $this->_backText . '</a></td></tr></table>';
$html .= '</td></tr><tr><td height="35%"></td></tr></table></body></html>';
echo $html;
self::$_isActive = false;
//
return true;
}
示例3: __construct
/**
* @inheritDoc
*/
public function __construct(\Throwable $t)
{
$this->message = $t->getMessage();
$this->code = $t->getCode();
$this->file = $t->getFile();
$this->line = $t->getLine();
}
示例4: display
/**
* Display the given exception to the user.
*
* @param \Exception $exception
* @return \Symfony\Component\HttpFoundation\Response
*/
public function display(\Throwable $exception)
{
if ($this->returnJson) {
return new JsonResponse(array('error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine()), 500);
}
return $this->symfony->createResponse($exception);
}
示例5: writeLogEntries
/**
* Writes exception to different logs
*
* @param \Exception|\Throwable $exception The exception(PHP 5.x) or throwable(PHP >= 7.0) object.
* @param string $context The context where the exception was thrown, WEB or CLI
* @return void
* @see \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog(), \TYPO3\CMS\Core\Utility\GeneralUtility::devLog()
* @TODO #72293 This will change to \Throwable only if we are >= PHP7.0 only
*/
protected function writeLogEntries($exception, $context)
{
// Do not write any logs for this message to avoid filling up tables or files with illegal requests
if ($exception->getCode() === 1396795884) {
return;
}
$filePathAndName = $exception->getFile();
$exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
$logTitle = 'Core: Exception handler (' . $context . ')';
$logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
if ($context === 'WEB') {
$logMessage .= '. Requested URL: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
}
$backtrace = $exception->getTrace();
// Write error message to the configured syslogs
GeneralUtility::sysLog($logMessage, $logTitle, GeneralUtility::SYSLOG_SEVERITY_FATAL);
// When database credentials are wrong, the exception is probably
// caused by this. Therefor we cannot do any database operation,
// otherwise this will lead into recurring exceptions.
try {
// Write error message to devlog
// see: $TYPO3_CONF_VARS['SYS']['enable_exceptionDLOG']
if (TYPO3_EXCEPTION_DLOG) {
GeneralUtility::devLog($logMessage, $logTitle, 3, array('TYPO3_MODE' => TYPO3_MODE, 'backtrace' => $backtrace));
}
// Write error message to sys_log table
$this->writeLog($logTitle . ': ' . $logMessage);
} catch (\Exception $exception) {
}
}
示例6: get
/**
* @inheritDoc
*/
public function get()
{
if (!isset($this->throwable)) {
throw new LogicException('Throwable must be set to get view.');
}
ob_start();
var_dump($this->throwable->getTrace());
$fullTrace = ob_get_clean();
// If xdebug is installed then var_dump is pretty printed for html already.
if (function_exists('xdebug_var_dump')) {
$viewTrace = new Text();
$viewTrace->setHTML5($fullTrace);
$fullTrace = ['div', ['class' => 'full_trace'], $viewTrace->get()];
} else {
$fullTrace = ['pre', ['class' => 'full_trace'], $fullTrace];
}
return ['div', ['class' => 'Throwable'], [['div', ['class' => 'location'], 'Thrown at ' . $this->throwable->getFile() . ' line ' . $this->throwable->getLine()], ['pre', [], $this->throwable->getMessage()], ['h2', [], 'Basic Trace'], ['pre', ['class' => 'basic_trace'], $this->throwable->getTraceAsString()], ['h2', [], 'Full Trace'], $fullTrace]];
}
示例7: logException
/**
* Shorthand: Logs the given Exception.
*
* @param Throwable|Exception $exception The Exception to log
*/
public static function logException($exception)
{
if ($exception instanceof ErrorException) {
self::logError($exception->getSeverity(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
} else {
$logger = self::factory();
$logger->log(get_class($exception), $exception->getMessage(), [], $exception->getFile(), $exception->getLine());
}
}
示例8: getResponseFormat
/**
* Method that returns a response in the request format
*
* @todo Customize according to project
* @param string $message Error message
* @param int $status Status code
* @param \Exception $exception Exception caught
* @return JsonResponse|HtmlResponse
*/
public function getResponseFormat($message, $status, \Throwable $exception)
{
if (count($this->accept) > 0 && $this->accept[0] == 'application/json') {
$data = ['status' => $status, 'error' => ['msg' => $message]];
if ($this->debug) {
$data['error']['debug']['msg'] = $exception->getMessage();
$data['error']['debug']['file'] = $exception->getFile();
$data['error']['debug']['line'] = $exception->getLine();
$data['error']['debug']['trace'] = $exception->getTrace();
}
return new JsonResponse($data, $status);
}
$msg = $message;
if ($this->debug) {
$msg .= '<br />Description: ' . $exception->getMessage();
$msg .= '<br />File: ' . $exception->getFile();
$msg .= '<br />Line: ' . $exception->getLine();
$msg .= '<br />Trace: ' . $exception->getTraceAsString();
}
return new HtmlResponse($msg, $status);
}
示例9: handle_exception
/**
* @param \Exception|\Throwable $exception
*/
public function handle_exception($exception)
{
if (getenv('APP_ENV') === 'dev') {
list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
$trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
echo "<b>Trace:</b><br>";
echo "<pre>{$trace_string}</pre>";
echo "<b>Debug:</b><br>";
dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
}
}
示例10: __construct
public function __construct(\Throwable $e)
{
if ($e instanceof \ParseError) {
$message = 'Parse error: ' . $e->getMessage();
$severity = E_PARSE;
} elseif ($e instanceof \TypeError) {
$message = 'Type error: ' . $e->getMessage();
$severity = E_RECOVERABLE_ERROR;
} else {
$message = $e->getMessage();
$severity = E_ERROR;
}
\ErrorException::__construct($message, $e->getCode(), $severity, $e->getFile(), $e->getLine());
$this->setTrace($e->getTrace());
}
示例11: error_log
/**
* 记录起始请求日志
* 记录成功返回true,失败或没记录日志返回false
*
* @param \Exception|\Throwable $ex
* @return bool
*/
public static function error_log($ex)
{
if (!BaseLog::isLog('error')) {
return false;
}
if (!Config::getEnv("app.framework_error_log")) {
return false;
}
$data = Request::nonPostParam();
if (Config::getEnv("app.request_log_post")) {
$data = Request::param();
}
$log_msg = "\r\nQP->Main最外层捕捉到Exception异常:\r\n请求参数:{Param}\r\n异常信息:{E_Msg}\r\n异常位置:{E_Point}\r\n更多异常队列信息:{E_Trace}\r\n";
$log_data = ['Param' => json_encode($data), 'E_Msg' => $ex->getMessage(), 'E_Point' => $ex->getFile() . ":" . $ex->getLine(), 'E_Trace' => json_encode($ex->getTrace())];
return Log::error($log_msg, $log_data, true, 'framework');
}
示例12: writeLogEntries
/**
* Writes exception to different logs
*
* @param \Exception|\Throwable $exception The exception(PHP 5.x) or throwable(PHP >= 7.0) object.
* @param string $context The context where the exception was thrown, WEB or CLI
* @return void
* @see \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog(), \TYPO3\CMS\Core\Utility\GeneralUtility::devLog()
*/
protected function writeLogEntries($exception, $context)
{
// Do not write any logs for this message to avoid filling up tables or files with illegal requests
if ($exception->getCode() === 1396795884) {
return;
}
$filePathAndName = $exception->getFile();
$exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
$logTitle = 'Core: Exception handler (' . $context . ')';
$logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
if ($context === self::CONTEXT_WEB) {
$logMessage .= '. Requested URL: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
}
// Write error message to the configured syslogs
GeneralUtility::sysLog($logMessage, $logTitle, GeneralUtility::SYSLOG_SEVERITY_FATAL);
}
示例13: exceptionHandler
public function exceptionHandler(\Throwable $exception)
{
$message = $exception->getMessage();
$values = $exception->getTrace();
$traces = [];
$trace = new Trace();
$trace->setFile($exception->getFile());
$trace->setLine($exception->getLine());
$trace->setClass(get_class($exception));
$traces[] = $trace;
foreach ($values as $value) {
$trace = new Trace();
$trace->setFile($this->getArrayValue($value, "file"));
$trace->setLine($this->getArrayValue($value, "line"));
$trace->setFunction($this->getArrayValue($value, "function"));
$trace->setClass($this->getArrayValue($value, "class"));
$traces[] = $trace;
}
$this->log($message, $traces);
}
示例14: send
/**
* @param \Throwable $t
* @throws \Comely\Framework\KernelException
* @throws \Comely\KnitException
*/
public function send(\Throwable $t)
{
$knit = (new Knit())->setTemplatePath(__DIR__)->setCompilerPath($this->kernel->getDisk("cache"));
// Extract information from \Throwable
$error = ["message" => null, "method" => null, "code" => $t->getCode(), "file" => $t->getFile(), "line" => $t->getLine(), "trace" => []];
// Check if exception has "getTranslated" method
$error["message"] = method_exists($t, "getTranslated") ? $t->getTranslated() : $t->getMessage();
// Check if exception is child of ComelyException
if (method_exists($t, "getMethod") && is_subclass_of($t, "ComelyException")) {
$error["method"] = $t->getMethod();
$error["source"] = "Component";
} else {
$error["method"] = get_class($t);
$error["source"] = "Caught";
}
// Populate Trace
foreach ($t->getTrace() as $trace) {
if (Arrays::hasKeys($trace, ["function", "file", "line"])) {
$trace["method"] = $trace["function"];
if (isset($trace["class"])) {
$trace["method"] = $trace["class"] . $trace["type"] . $trace["function"];
}
$error["trace"][] = $trace;
}
}
// Config
$config = $this->kernel->config()->getNode("app");
$display = ["backtrace" => $config["errorHandler"]["screen"]["debugBacktrace"] ?? false, "triggered" => $config["errorHandler"]["screen"]["triggeredErrors"] ?? false, "paths" => $config["errorHandler"]["screen"]["completePaths"] ?? false];
// Assign values
$knit->assign("display", $display);
$knit->assign("error", $error);
$knit->assign("triggered", $this->kernel->errorHandler()->fetchAll());
$knit->assign("version", ["comely" => \Comely::VERSION, "kernel" => Kernel::VERSION, "framework" => Kernel::VERSION, "knit" => Knit::VERSION]);
// Prepare template
$screen = $knit->prepare("screen.knit");
$screen = str_replace("%%knit-timer%%", number_format($screen->getTimer(), 6, ".", ""), $screen->getOutput());
exit($screen);
}
示例15: decodeException
/**
* Decodes an exception and retrieves the correct caller.
*
* @param \Exception|\Throwable $exception
* The exception object that was thrown.
*
* @return array
* An error in the format expected by _drupal_log_error().
*/
public static function decodeException($exception)
{
$message = $exception->getMessage();
$backtrace = $exception->getTrace();
// Add the line throwing the exception to the backtrace.
array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
// For PDOException errors, we try to return the initial caller,
// skipping internal functions of the database layer.
if ($exception instanceof \PDOException || $exception instanceof DatabaseExceptionWrapper) {
// The first element in the stack is the call, the second element gives us
// the caller. We skip calls that occurred in one of the classes of the
// database layer or in one of its global functions.
$db_functions = array('db_query', 'db_query_range');
while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions))) {
// We remove that call.
array_shift($backtrace);
}
if (isset($exception->query_string, $exception->args)) {
$message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
}
}
$caller = static::getLastCaller($backtrace);
return array('%type' => get_class($exception), '@message' => $message, '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => static::ERROR, 'backtrace' => $backtrace, '@backtrace_string' => $exception->getTraceAsString());
}