@@ -117,6 +117,7 @@ discard block |
||
| 117 | 117 | * It terminates the application immediately after the error is displayed. |
| 118 | 118 | * @param mixed sender of the event |
| 119 | 119 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
| 120 | + * @param null|\Prado\TApplication $sender |
|
| 120 | 121 | */ |
| 121 | 122 | public function handleError($sender,$param) |
| 122 | 123 | { |
@@ -186,6 +187,7 @@ discard block |
||
| 186 | 187 | * mode will be displayed to the client user. |
| 187 | 188 | * @param integer response status code |
| 188 | 189 | * @param Exception exception instance |
| 190 | + * @param integer $statusCode |
|
| 189 | 191 | */ |
| 190 | 192 | protected function handleExternalError($statusCode,$exception) |
| 191 | 193 | { |
@@ -382,6 +384,9 @@ discard block |
||
| 382 | 384 | return $result; |
| 383 | 385 | } |
| 384 | 386 | |
| 387 | + /** |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 385 | 390 | private function getExactTraceAsString($exception) |
| 386 | 391 | { |
| 387 | 392 | if($exception instanceof TPhpFatalErrorException && |
@@ -409,6 +414,9 @@ discard block |
||
| 409 | 414 | return $exception->getTraceAsString(); |
| 410 | 415 | } |
| 411 | 416 | |
| 417 | + /** |
|
| 418 | + * @param string $pattern |
|
| 419 | + */ |
|
| 412 | 420 | private function getPropertyAccessTrace($trace,$pattern) |
| 413 | 421 | { |
| 414 | 422 | $result=null; |
@@ -441,6 +449,9 @@ discard block |
||
| 441 | 449 | return $source; |
| 442 | 450 | } |
| 443 | 451 | |
| 452 | + /** |
|
| 453 | + * @param string $message |
|
| 454 | + */ |
|
| 444 | 455 | private function addLink($message) { |
| 445 | 456 | if (!is_null($class = $this->getErrorClassNameSpace($message))) { |
| 446 | 457 | return str_replace($class['name'], '<a href="' . $class['url'] . '" target="_blank">' . $class['name'] . '</a>', $message); |
@@ -461,8 +461,8 @@ |
||
| 461 | 461 | } |
| 462 | 462 | $classname = $function->getNamespaceName(); |
| 463 | 463 | return [ |
| 464 | - 'url' => 'http://pradosoft.github.io/docs/manual/class-' . str_replace('\\', '.', (string) $classname) . '.' . $class . '.html', |
|
| 465 | - 'name' => $class, |
|
| 464 | + 'url' => 'http://pradosoft.github.io/docs/manual/class-' . str_replace('\\', '.', (string) $classname) . '.' . $class . '.html', |
|
| 465 | + 'name' => $class, |
|
| 466 | 466 | ]; |
| 467 | 467 | } |
| 468 | 468 | return null; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if(($templatePath=Prado::getPathOfNamespace($value))!==null && is_dir($templatePath)) |
| 107 | 107 | $this->_templatePath=$templatePath; |
| 108 | 108 | else |
| 109 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid',$value); |
|
| 109 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param mixed sender of the event |
| 119 | 119 | * @param mixed event parameter (if the event is raised by TApplication, it refers to the exception instance) |
| 120 | 120 | */ |
| 121 | - public function handleError($sender,$param) |
|
| 121 | + public function handleError($sender, $param) |
|
| 122 | 122 | { |
| 123 | 123 | static $handling=false; |
| 124 | 124 | // We need to restore error and exception handlers, |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | if(!headers_sent()) |
| 138 | 138 | header('Content-Type: text/html; charset=UTF-8'); |
| 139 | 139 | if($param instanceof THttpException) |
| 140 | - $this->handleExternalError($param->getStatusCode(),$param); |
|
| 140 | + $this->handleExternalError($param->getStatusCode(), $param); |
|
| 141 | 141 | else if($this->getApplication()->getMode()===TApplicationMode::Debug) |
| 142 | 142 | $this->displayException($param); |
| 143 | 143 | else |
| 144 | - $this->handleExternalError(500,$param); |
|
| 144 | + $this->handleExternalError(500, $param); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -154,28 +154,28 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected static function hideSecurityRelated($value, $exception=null) |
| 156 | 156 | { |
| 157 | - $aRpl = array(); |
|
| 158 | - if($exception !== null && $exception instanceof \Exception) |
|
| 157 | + $aRpl=array(); |
|
| 158 | + if($exception!==null && $exception instanceof \Exception) |
|
| 159 | 159 | { |
| 160 | 160 | if($exception instanceof TPhpFatalErrorException && |
| 161 | 161 | function_exists('xdebug_get_function_stack')) |
| 162 | 162 | { |
| 163 | - $aTrace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 163 | + $aTrace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 164 | 164 | } else { |
| 165 | - $aTrace = $exception->getTrace(); |
|
| 165 | + $aTrace=$exception->getTrace(); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | foreach($aTrace as $item) |
| 169 | 169 | { |
| 170 | 170 | if(isset($item['file'])) |
| 171 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
| 171 | + $aRpl[dirname($item['file']).DIRECTORY_SEPARATOR]='<hidden>'.DIRECTORY_SEPARATOR; |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | - $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
|
| 175 | - $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
|
| 176 | - $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
|
| 174 | + $aRpl[$_SERVER['DOCUMENT_ROOT']]='${DocumentRoot}'; |
|
| 175 | + $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])]='${DocumentRoot}'; |
|
| 176 | + $aRpl[PRADO_DIR.DIRECTORY_SEPARATOR]='${PradoFramework}'.DIRECTORY_SEPARATOR; |
|
| 177 | 177 | if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
| 178 | - $aRpl = array_reverse($aRpl, true); |
|
| 178 | + $aRpl=array_reverse($aRpl, true); |
|
| 179 | 179 | |
| 180 | 180 | return str_replace(array_keys($aRpl), $aRpl, $value); |
| 181 | 181 | } |
@@ -187,36 +187,36 @@ discard block |
||
| 187 | 187 | * @param integer response status code |
| 188 | 188 | * @param Exception exception instance |
| 189 | 189 | */ |
| 190 | - protected function handleExternalError($statusCode,$exception) |
|
| 190 | + protected function handleExternalError($statusCode, $exception) |
|
| 191 | 191 | { |
| 192 | 192 | if(!($exception instanceof THttpException)) |
| 193 | 193 | error_log($exception->__toString()); |
| 194 | 194 | |
| 195 | - $content=$this->getErrorTemplate($statusCode,$exception); |
|
| 195 | + $content=$this->getErrorTemplate($statusCode, $exception); |
|
| 196 | 196 | |
| 197 | - $serverAdmin=isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
|
| 197 | + $serverAdmin=isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : ''; |
|
| 198 | 198 | |
| 199 | - $isDebug = $this->getApplication()->getMode()===TApplicationMode::Debug; |
|
| 199 | + $isDebug=$this->getApplication()->getMode()===TApplicationMode::Debug; |
|
| 200 | 200 | |
| 201 | - $errorMessage = $exception->getMessage(); |
|
| 201 | + $errorMessage=$exception->getMessage(); |
|
| 202 | 202 | if($isDebug) |
| 203 | 203 | $version=$_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
| 204 | 204 | else |
| 205 | 205 | { |
| 206 | 206 | $version=''; |
| 207 | - $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
|
| 207 | + $errorMessage=self::hideSecurityRelated($errorMessage, $exception); |
|
| 208 | 208 | } |
| 209 | 209 | $tokens=array( |
| 210 | 210 | '%%StatusCode%%' => "$statusCode", |
| 211 | 211 | '%%ErrorMessage%%' => htmlspecialchars($errorMessage), |
| 212 | 212 | '%%ServerAdmin%%' => $serverAdmin, |
| 213 | 213 | '%%Version%%' => $version, |
| 214 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
| 214 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
| 215 | 215 | ); |
| 216 | 216 | |
| 217 | 217 | $this->getApplication()->getResponse()->setStatusCode($statusCode, $isDebug ? $exception->getMessage() : null); |
| 218 | 218 | |
| 219 | - echo strtr($content,$tokens); |
|
| 219 | + echo strtr($content, $tokens); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | if($exception instanceof TTemplateException) |
| 262 | 262 | { |
| 263 | 263 | $fileName=$exception->getTemplateFile(); |
| 264 | - $lines=empty($fileName)?explode("\n",$exception->getTemplateSource()):@file($fileName); |
|
| 265 | - $source=$this->getSourceCode($lines,$exception->getLineNumber()); |
|
| 264 | + $lines=empty($fileName) ?explode("\n", $exception->getTemplateSource()) : @file($fileName); |
|
| 265 | + $source=$this->getSourceCode($lines, $exception->getLineNumber()); |
|
| 266 | 266 | if($fileName==='') |
| 267 | 267 | $fileName='---embedded template---'; |
| 268 | 268 | $errorLine=$exception->getLineNumber(); |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $fileName=$exception->getFile(); |
| 280 | 280 | $errorLine=$exception->getLine(); |
| 281 | 281 | } |
| 282 | - $source=$this->getSourceCode(@file($fileName),$errorLine); |
|
| 282 | + $source=$this->getSourceCode(@file($fileName), $errorLine); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | if($this->getApplication()->getMode()===TApplicationMode::Debug) |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | '%%SourceCode%%' => $source, |
| 295 | 295 | '%%StackTrace%%' => htmlspecialchars($this->getExactTraceAsString($exception)), |
| 296 | 296 | '%%Version%%' => $version, |
| 297 | - '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) |
|
| 297 | + '%%Time%%' => @strftime('%Y-%m-%d %H:%M', time()) |
|
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | 300 | $content=$this->getExceptionTemplate($exception); |
| 301 | 301 | |
| 302 | - echo strtr($content,$tokens); |
|
| 302 | + echo strtr($content, $tokens); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * @param Exception the exception to be displayed |
| 337 | 337 | * @return string the template content |
| 338 | 338 | */ |
| 339 | - protected function getErrorTemplate($statusCode,$exception) |
|
| 339 | + protected function getErrorTemplate($statusCode, $exception) |
|
| 340 | 340 | { |
| 341 | 341 | $base=$this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
| 342 | 342 | $lang=Prado::getPreferredLanguage(); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | if($exception instanceof TPhpFatalErrorException && |
| 360 | 360 | function_exists('xdebug_get_function_stack')) |
| 361 | 361 | { |
| 362 | - $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 362 | + $trace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 363 | 363 | } else { |
| 364 | 364 | $trace=$exception->getTrace(); |
| 365 | 365 | } |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | $result=$trace[1]; |
| 374 | 374 | } elseif($exception instanceof TInvalidOperationException) { |
| 375 | 375 | // in case of getter or setter error, find out the exact file and row |
| 376 | - if(($result=$this->getPropertyAccessTrace($trace,'__get'))===null) |
|
| 377 | - $result=$this->getPropertyAccessTrace($trace,'__set'); |
|
| 376 | + if(($result=$this->getPropertyAccessTrace($trace, '__get'))===null) |
|
| 377 | + $result=$this->getPropertyAccessTrace($trace, '__set'); |
|
| 378 | 378 | } |
| 379 | - if($result!==null && strpos($result['file'],': eval()\'d code')!==false) |
|
| 379 | + if($result!==null && strpos($result['file'], ': eval()\'d code')!==false) |
|
| 380 | 380 | return null; |
| 381 | 381 | |
| 382 | 382 | return $result; |
@@ -387,19 +387,19 @@ discard block |
||
| 387 | 387 | if($exception instanceof TPhpFatalErrorException && |
| 388 | 388 | function_exists('xdebug_get_function_stack')) |
| 389 | 389 | { |
| 390 | - $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 391 | - $txt = ''; |
|
| 392 | - $row = 0; |
|
| 390 | + $trace=array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
|
| 391 | + $txt=''; |
|
| 392 | + $row=0; |
|
| 393 | 393 | |
| 394 | 394 | // try to mimic Exception::getTraceAsString() |
| 395 | 395 | foreach($trace as $line) |
| 396 | 396 | { |
| 397 | 397 | if(array_key_exists('function', $line)) |
| 398 | - $func = $line['function'] . '(' . implode(',', $line['params']) . ')'; |
|
| 398 | + $func=$line['function'].'('.implode(',', $line['params']).')'; |
|
| 399 | 399 | else |
| 400 | - $func = 'unknown'; |
|
| 400 | + $func='unknown'; |
|
| 401 | 401 | |
| 402 | - $txt .= '#' . $row . ' ' . $line['file'] . '(' . $line['line'] . '): ' . $func . "\n"; |
|
| 402 | + $txt.='#'.$row.' '.$line['file'].'('.$line['line'].'): '.$func."\n"; |
|
| 403 | 403 | $row++; |
| 404 | 404 | } |
| 405 | 405 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | return $exception->getTraceAsString(); |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - private function getPropertyAccessTrace($trace,$pattern) |
|
| 412 | + private function getPropertyAccessTrace($trace, $pattern) |
|
| 413 | 413 | { |
| 414 | 414 | $result=null; |
| 415 | 415 | foreach($trace as $t) |
@@ -422,46 +422,46 @@ discard block |
||
| 422 | 422 | return $result; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - private function getSourceCode($lines,$errorLine) |
|
| 425 | + private function getSourceCode($lines, $errorLine) |
|
| 426 | 426 | { |
| 427 | - $beginLine=$errorLine-self::SOURCE_LINES>=0?$errorLine-self::SOURCE_LINES:0; |
|
| 428 | - $endLine=$errorLine+self::SOURCE_LINES<=count($lines)?$errorLine+self::SOURCE_LINES:count($lines); |
|
| 427 | + $beginLine=$errorLine - self::SOURCE_LINES >= 0 ? $errorLine - self::SOURCE_LINES : 0; |
|
| 428 | + $endLine=$errorLine + self::SOURCE_LINES <= count($lines) ? $errorLine + self::SOURCE_LINES : count($lines); |
|
| 429 | 429 | |
| 430 | 430 | $source=''; |
| 431 | - for($i=$beginLine;$i<$endLine;++$i) |
|
| 431 | + for($i=$beginLine; $i < $endLine; ++$i) |
|
| 432 | 432 | { |
| 433 | - if($i===$errorLine-1) |
|
| 433 | + if($i===$errorLine - 1) |
|
| 434 | 434 | { |
| 435 | - $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 435 | + $line=htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
| 436 | 436 | $source.="<div class=\"error\">".$line."</div>"; |
| 437 | 437 | } |
| 438 | 438 | else |
| 439 | - $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
|
| 439 | + $source.=htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
| 440 | 440 | } |
| 441 | 441 | return $source; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | private function addLink($message) { |
| 445 | - if (!is_null($class = $this->getErrorClassNameSpace($message))) { |
|
| 446 | - return str_replace($class['name'], '<a href="' . $class['url'] . '" target="_blank">' . $class['name'] . '</a>', $message); |
|
| 445 | + if(!is_null($class=$this->getErrorClassNameSpace($message))) { |
|
| 446 | + return str_replace($class['name'], '<a href="'.$class['url'].'" target="_blank">'.$class['name'].'</a>', $message); |
|
| 447 | 447 | } |
| 448 | 448 | return $message; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | private function getErrorClassNameSpace($message) { |
| 452 | - $matches = []; |
|
| 452 | + $matches=[]; |
|
| 453 | 453 | preg_match('/\b(T[A-Z]\w+)\b/', $message, $matches); |
| 454 | - if (is_array($matches) && count($matches) > 0) { |
|
| 455 | - $class = $matches[0]; |
|
| 454 | + if(is_array($matches) && count($matches) > 0) { |
|
| 455 | + $class=$matches[0]; |
|
| 456 | 456 | try { |
| 457 | - $function = new \ReflectionClass($class); |
|
| 457 | + $function=new \ReflectionClass($class); |
|
| 458 | 458 | } |
| 459 | - catch (\Exception $e) { |
|
| 459 | + catch(\Exception $e) { |
|
| 460 | 460 | return null; |
| 461 | 461 | } |
| 462 | - $classname = $function->getNamespaceName(); |
|
| 462 | + $classname=$function->getNamespaceName(); |
|
| 463 | 463 | return [ |
| 464 | - 'url' => 'http://pradosoft.github.io/docs/manual/class-' . str_replace('\\', '.', (string) $classname) . '.' . $class . '.html', |
|
| 464 | + 'url' => 'http://pradosoft.github.io/docs/manual/class-'.str_replace('\\', '.', (string) $classname).'.'.$class.'.html', |
|
| 465 | 465 | 'name' => $class, |
| 466 | 466 | ]; |
| 467 | 467 | } |
@@ -234,8 +234,7 @@ discard block |
||
| 234 | 234 | echo "<body><h1>Recursive Error</h1>\n"; |
| 235 | 235 | echo "<pre>".$exception->__toString()."</pre>\n"; |
| 236 | 236 | echo "</body></html>"; |
| 237 | - } |
|
| 238 | - else |
|
| 237 | + } else |
|
| 239 | 238 | { |
| 240 | 239 | error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
| 241 | 240 | header('HTTP/1.0 500 Internal Error'); |
@@ -266,15 +265,13 @@ discard block |
||
| 266 | 265 | if($fileName==='') |
| 267 | 266 | $fileName='---embedded template---'; |
| 268 | 267 | $errorLine=$exception->getLineNumber(); |
| 269 | - } |
|
| 270 | - else |
|
| 268 | + } else |
|
| 271 | 269 | { |
| 272 | 270 | if(($trace=$this->getExactTrace($exception))!==null) |
| 273 | 271 | { |
| 274 | 272 | $fileName=$trace['file']; |
| 275 | 273 | $errorLine=$trace['line']; |
| 276 | - } |
|
| 277 | - else |
|
| 274 | + } else |
|
| 278 | 275 | { |
| 279 | 276 | $fileName=$exception->getFile(); |
| 280 | 277 | $errorLine=$exception->getLine(); |
@@ -434,8 +431,7 @@ discard block |
||
| 434 | 431 | { |
| 435 | 432 | $line=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
| 436 | 433 | $source.="<div class=\"error\">".$line."</div>"; |
| 437 | - } |
|
| 438 | - else |
|
| 434 | + } else |
|
| 439 | 435 | $source.=htmlspecialchars(sprintf("%04d: %s",$i+1,str_replace("\t",' ',$lines[$i]))); |
| 440 | 436 | } |
| 441 | 437 | return $source; |
@@ -455,8 +451,7 @@ discard block |
||
| 455 | 451 | $class = $matches[0]; |
| 456 | 452 | try { |
| 457 | 453 | $function = new \ReflectionClass($class); |
| 458 | - } |
|
| 459 | - catch (\Exception $e) { |
|
| 454 | + } catch (\Exception $e) { |
|
| 460 | 455 | return null; |
| 461 | 456 | } |
| 462 | 457 | $classname = $function->getNamespaceName(); |