|
Server IP : 10.2.73.233 / Your IP : 216.73.216.59 Web Server : Apache/2.4.59 (Debian) System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : www-data ( 33) PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/ilpnowa/../ifk/web.back/protected/Common/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
Prado::using('System.Exceptions.TErrorHandler');
class PErrorHandler extends TErrorHandler
{
/*protected function handleExternalError($statusCode, $exception)
{
if(!headers_sent())
header("HTTP/1.0 {$statusCode} {$exception->getMessage()}");
parent::handleExternalError($statusCode, $exception);
}*/
public function handleError($sender,$param)
{
if ($this->Application->Mode == 'Debug') {
parent::handleError($sender, $param);
die();
}
static $handling=false;
// We need to restore error and exception handlers,
// because within error and exception handlers, new errors and exceptions
// cannot be handled properly by PHP
restore_error_handler();
restore_exception_handler();
// ensure that we do not enter infinite loop of error handling
if($handling)
$this->handleRecursiveError($param);
else
{
$handling=true;
if(($response=$this->getResponse())!==null)
$response->clear();
if(!headers_sent()) {
header("HTTP/1.0 500", true, 500);
header('Content-Type: text/html; charset=UTF-8');
}
$this->sendErrorEmail($param);
include('static/error.html');
die();
}
}
protected function sendErrorEmail($exception)
{
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);
}
$messageBody = "TYP BŁĘDU:\n".get_class($exception).
"\n\nKOMUNIKAT:\n".$exception->getMessage().
"\n\nW PLIKU:\n".$fileName.' (linia #'.$errorLine.')'.
"\n\nŹRÓDŁO:\n".$source.
"\n\nSTACK TRACE:\n".$exception->getTraceAsString().
"\n\nCZAS SERWEROWY WYSTĄPIENIA:\n".@date(DATE_ATOM).
"\n\nSERVER:\n".print_r($_SERVER, true).
"\n\nREQUEST:\n".print_r($this->Request, true);
$content=$this->getExceptionTemplate($exception);
PEmailer::sendError($messageBody, get_class($exception)." @ $fileName (linia #$errorLine)", "[APP]");
}
/* ------------------------------------------------------------------------------------------------------------ */
private function getExactTrace($exception)
{
$trace=$exception->getTrace();
$result=null;
// 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($exception instanceof TPhpErrorException)
$result=isset($trace[0]['file'])?$trace[0]:$trace[1];
else if($exception instanceof TInvalidOperationException)
{
// in case of getter or setter error, find out the exact file and row
if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null)
$result=$this->getPropertyAccessTrace($trace,'__set');
}
if($result!==null && strpos($result['file'],': eval()\'d code')!==false)
return null;
return $result;
}
private function getPropertyAccessTrace($trace,$pattern)
{
$result=null;
foreach($trace as $t)
{
if(isset($t['function']) && $t['function']===$pattern)
$result=$t;
else
break;
}
return $result;
}
private function getSourceCode($lines,$errorLine)
{
$beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0;
$endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines);
$source='';
for($i=$beginLine;$i<$endLine;++$i)
{
if($i===$errorLine-1)
{
$line=sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]));
$source.="***********\n".$line."***********\n";
}
else
$source.=sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]));
}
return $source;
}
private function addLink($message)
{
$baseUrl='http://www.pradosoft.com/docs/classdoc';
return preg_replace('/\b(T[A-Z]\w+)\b/',"<a href=\"$baseUrl/\${1}\" target=\"_blank\">\${1}</a>",$message);
}
}
?>