outputError() public static method

public static outputError ( $file, $data = [] )
Ejemplo n.º 1
0
 public static function outputError($message = null)
 {
     // Write the error to log file
     @error_log('Error 404 Page Not Found: ' . $_SERVER['REQUEST_URI']);
     header('HTTP/1.1 404 Not Found', true, 500);
     \Resources\Controller::outputError('errors/404', array('message' => $message));
 }
Ejemplo n.º 2
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']);
     header('HTTP/1.1 404 Not Found', true, 500);
     \Resources\Controller::outputError('errors/404', array('message' => $exception->getMessage()));
 }
Ejemplo n.º 3
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 (array_search('views', explode('/', $file)) !== false || PHP_SAPI == 'cli') {
         exit($errorMessage);
     }
     $code = array();
     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 < 0) {
         $startIterate = 0;
     }
     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">' . $getLine[$i] . "</span>\n";
         } else {
             $html .= $getLine[$i] . "\n";
         }
         $code[] = $html;
     }
     constructViewData:
     $data = array('message' => $message, 'file' => $file, 'line' => $line, 'code' => $code, 'trace' => $trace);
     header("HTTP/1.1 500 Internal Server Error", true, 500);
     \Resources\Controller::outputError('errors/500', $data);
     exit(1);
 }