Example #1
0
 public static function outputError($exception)
 {
     if (PHP_SAPI == 'cli') {
         echo $exception->getMessage() . "\nFile: " . $exception->getFile() . ' on line ' . $exception->getLine() . "\n\n" . $exception->getTraceAsString() . "\n";
         // exit with an error code
         exit(1);
     }
     // Write the error to log file
     @error_log('Error 404 Page Not Found: ' . $_SERVER['REQUEST_URI']);
     $response = new Response();
     $response->setStatusCode(404);
     $response->setBody(Controller::outputError('errors/404', ['message' => $exception->getMessage()]));
     return $response;
 }
Example #2
0
 public static function outputError($message = null, $file = false, $line = false, $trace = false)
 {
     // Message for log
     $errorMessage = 'Error ' . $message . ' in ' . $file . ' line: ' . $line;
     // Write the error to log file
     @error_log($errorMessage);
     // Just output the error if the error source for view file or if in cli mode.
     if (PHP_SAPI == 'cli') {
         exit($errorMessage);
     }
     $code = [];
     if (!$file) {
         goto constructViewData;
     }
     $fileString = file_get_contents($file);
     $arrLine = explode("\n", $fileString);
     $totalLine = count($arrLine);
     $getLine = array_combine(range(1, $totalLine), array_values($arrLine));
     $startIterate = $line - 5;
     $endIterate = $line + 5;
     if ($startIterate < 1) {
         $startIterate = 1;
     }
     if ($endIterate > $totalLine) {
         $endIterate = $totalLine;
     }
     for ($i = $startIterate; $i <= $endIterate; $i++) {
         $html = '<span style="margin-right:10px;background:#CFCFCF;">' . $i . '</span>';
         if ($line == $i) {
             $html .= '<span style="color:#DD0000">' . htmlentities($getLine[$i]) . "</span>\n";
         } else {
             $html .= htmlentities($getLine[$i]) . "\n";
         }
         $code[] = $html;
     }
     constructViewData:
     $data = ['message' => $message, 'file' => $file, 'line' => $line, 'code' => $code, 'trace' => $trace];
     $response = new Response();
     $response->setStatusCode(500);
     $response->setBody(Controller::outputError('errors/500', $data));
     return $response;
 }