PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/system/handler/error.php

https://github.com/benphelps/Phelps-Framework
PHP | 101 lines | 42 code | 13 blank | 46 comment | 1 complexity | c2b1f74b3210cdbf02374829b8bb95f4 MD5 | raw file
  1<?php
  2/**
  3 * PhelpsFramework Core
  4 *
  5 * @author Ben Phelps
  6 * @version 0.2
  7 * @copyright 2012 benphelps.me
  8 * @package PhelpsFramework
  9 **/
 10
 11/**
 12 * @package PhelpsFramework;
 13 */
 14namespace PhelpsFramework;
 15
 16/**
 17 * Error handler and thrower.
 18 *
 19 * @package PhelpsFramework
 20 * @author Ben Phelps
 21 */
 22class Error
 23{
 24
 25  /**
 26   * List of textual representation of error levels
 27   *
 28   * @var array $levels Array of error levels
 29   */
 30  var $levels = [
 31    E_ERROR           =>  'Error',
 32    E_WARNING         =>  'Warning',
 33    E_PARSE           =>  'Parsing Error',
 34    E_NOTICE          =>  'Notice',
 35    E_CORE_ERROR      =>  'Core Error',
 36    E_CORE_WARNING    =>  'Core Warning',
 37    E_COMPILE_ERROR   =>  'Compile Error',
 38    E_COMPILE_WARNING =>  'Compile Warning',
 39    E_USER_ERROR      =>  'User Error',
 40    E_USER_WARNING    =>  'User Warning',
 41    E_USER_NOTICE     =>  'User Notice',
 42    E_STRICT          =>  'Notice',
 43  ];
 44  
 45  /**
 46   * Throws a fatal error and stops script execution
 47   *
 48   * @param string $errstr 
 49   * @return void
 50   * @author Ben Phelps
 51   */
 52  public static function fatal($errstr)
 53  {
 54    $error = 'Fatal Framework Error';
 55    include(SYS_DIR . 'handler/template/framework.php');
 56    die();
 57  }
 58  
 59  /**
 60   * Throws a 404 File Not Found error and stops script execution
 61   *
 62   * @return void
 63   * @author Ben Phelps
 64   */
 65  public static function _404()
 66  {
 67    include(SYS_DIR . 'handler/template/404.php');
 68    die();
 69  }
 70
 71  /**
 72   * Error handler
 73   *
 74   * @param string $errno 
 75   * @param string $errstr 
 76   * @param string $errfile 
 77   * @param string $errline 
 78   * @return void
 79   * @author Ben Phelps
 80   */
 81  public function handler($errno, $errstr, $errfile, $errline)
 82  {
 83    
 84    if (FALSE !== strpos($errfile, '/'))
 85    {
 86      $x = explode('/', $errfile);
 87      $errfile = $x[count($x)-2].'/'.end($x);
 88    }
 89    
 90    $error = $this->levels[$errno];
 91    
 92    include(SYS_DIR . 'handler/template/error.php');
 93    
 94    return true;
 95  }
 96
 97}
 98
 99set_error_handler([new Error, 'handler']);
100
101// EOF