/** * @param Exception exception details. * @return array exception stack trace details. */ private function getExceptionStackTrace($exception) { $data['code'] = $exception->getCode() > 0 ? $exception->getCode() : 500; $data['file'] = $exception->getFile(); $data['line'] = $exception->getLine(); $data['trace'] = $exception->getTrace(); if ($exception instanceof TPhpErrorException) { // if PHP exception, we want to show the 2nd stack level context // because the 1st stack level is of little use (it's in error handler) if (isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) { $data['file'] = $trace[0]['file']; $data['line'] = $trace[0]['line']; } } $data['type'] = get_class($exception); $data['message'] = $exception->getMessage(); $data['version'] = $_SERVER['SERVER_SOFTWARE'] . ' ' . Prado::getVersion(); $data['time'] = @strftime('%Y-%m-%d %H:%M', time()); return $data; }
/** * Generate a CRC32 hash for the directory path. Collisions are higher * than MD5 but generates a much smaller hash string. * @param string string to be hashed. * @return string hashed string. */ protected function hash($dir) { return sprintf('%x', crc32($dir . Prado::getVersion())); }
/** * Displays exception information. * Exceptions are displayed with rich context information, including * the call stack and the context source code. * This method is only invoked when application is in <b>Debug</b> mode. * @param Exception exception instance */ protected function displayException($exception) { if (php_sapi_name() === 'cli') { echo $exception->getMessage() . "\n"; echo $exception->getTraceAsString(); return; } if ($exception instanceof TTemplateException) { $fileName = $exception->getTemplateFile(); $lines = empty($fileName) ? explode("\n", $exception->getTemplateSource()) : @file($fileName); $source = $this->getSourceCode($lines, $exception->getLineNumber()); if ($fileName === '') { $fileName = '---embedded template---'; } $errorLine = $exception->getLineNumber(); } else { if (($trace = $this->getExactTrace($exception)) !== null) { $fileName = $trace['file']; $errorLine = $trace['line']; } else { $fileName = $exception->getFile(); $errorLine = $exception->getLine(); } $source = $this->getSourceCode(@file($fileName), $errorLine); } if ($this->getApplication()->getMode() === TApplicationMode::Debug) { $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado4">PRADO</a>/' . Prado::getVersion(); } else { $version = ''; } $tokens = array('%%ErrorType%%' => get_class($exception), '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', '%%SourceCode%%' => $source, '%%StackTrace%%' => htmlspecialchars($exception->getTraceAsString()), '%%Version%%' => $version, '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time())); $content = $this->getExceptionTemplate($exception); echo strtr($content, $tokens); }