Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • Hawk\App
  • Hawk\ButtonInput
  • Hawk\Cache
  • Hawk\CheckboxInput
  • Hawk\ColorInput
  • Hawk\Conf
  • Hawk\Controller
  • Hawk\Crypto
  • Hawk\DatabaseSessionHandler
  • Hawk\DatetimeInput
  • Hawk\DB
  • Hawk\DBExample
  • Hawk\DeleteInput
  • Hawk\Dialogbox
  • Hawk\EmailInput
  • Hawk\ErrorHandler
  • Hawk\Event
  • Hawk\FileInput
  • Hawk\FileSystem
  • Hawk\FloatInput
  • Hawk\Form
  • Hawk\FormFieldset
  • Hawk\FormInput
  • Hawk\GenericModel
  • Hawk\GifImage
  • Hawk\HawkApi
  • Hawk\HawkUpdater
  • Hawk\HiddenInput
  • Hawk\HtmlInput
  • Hawk\HTTPRequest
  • Hawk\Icon
  • Hawk\Image
  • Hawk\IntegerInput
  • Hawk\ItemList
  • Hawk\ItemListField
  • Hawk\JpegImage
  • Hawk\Lang
  • Hawk\Language
  • Hawk\LeftSidebarTab
  • Hawk\Less
  • Hawk\Logger
  • Hawk\Mail
  • Hawk\MenuItem
  • Hawk\Model
  • Hawk\NoSidebarTab
  • Hawk\NumberInput
  • Hawk\ObjectInput
  • Hawk\Option
  • Hawk\Panel
  • Hawk\PasswordInput
  • Hawk\Permission
  • Hawk\Plugin
  • Hawk\PluginInstaller
  • Hawk\PngImage
  • Hawk\ProfileQuestion
  • Hawk\ProfileQuestionValue
  • Hawk\RadioInput
  • Hawk\Request
  • Hawk\Response
  • Hawk\RightSidebarTab
  • Hawk\Role
  • Hawk\RolePermission
  • Hawk\Route
  • Hawk\Router
  • Hawk\SelectInput
  • Hawk\Session
  • Hawk\Singleton
  • Hawk\SubmitInput
  • Hawk\Tabs
  • Hawk\TextareaInput
  • Hawk\TextInput
  • Hawk\Theme
  • Hawk\TimeInput
  • Hawk\Upload
  • Hawk\User
  • Hawk\View
  • Hawk\View\Plugins\Accordion
  • Hawk\View\Plugins\Button
  • Hawk\View\Plugins\Form
  • Hawk\View\Plugins\Icon
  • Hawk\View\Plugins\Import
  • Hawk\View\Plugins\Panel
  • Hawk\View\Plugins\Tabs
  • Hawk\View\Plugins\Text
  • Hawk\View\Plugins\Uri
  • Hawk\View\Plugins\Widget
  • Hawk\ViewPlugin
  • Hawk\Widget
  • Hawk\WysiwygInput

Traits

  • Hawk\Utils

Exceptions

  • Hawk\AppStopException
  • Hawk\DBExampleException
  • Hawk\DBException
  • Hawk\FileSystemException
  • Hawk\HawkApiException
  • Hawk\ImageException
  • Hawk\MailException
  • Hawk\UploadException
  • Hawk\ViewException
  1 <?php
  2 /**
  3  * ErrorHandler.php
  4  *
  5  * @author  Elvyrra
  6  * @license http://rem.mit-license.org/ MIT
  7  */
  8 
  9 namespace Hawk;
 10 
 11 /**
 12  * This class defines the errors and exceptions handlers
 13  *
 14  * @package Core
 15  */
 16 final class ErrorHandler extends Singleton{
 17 
 18     /**
 19      * The error handler instance
 20      */
 21     protected static $instance;
 22 
 23     /**
 24      * Handler an error
 25      *
 26      * @param int    $no      The error number
 27      * @param string $str     The error message
 28      * @param string $file    The file that throwed the error
 29      * @param int    $line    The line in the file where the error was throwed
 30      * @param array  $context All the variables in the error context
 31      */
 32     public function error($no, $str, $file, $line, $context){
 33         if (!(error_reporting() & $no)) {
 34             // This error code is not in error_reporting
 35             return;
 36         }
 37 
 38         switch($no){
 39             case E_NOTICE :
 40             case E_USER_NOTICE:
 41                 $level = "info";
 42                 $icon = 'info-circle';
 43                 $title = "PHP Notice";
 44                 App::logger()->notice($str);
 45                 break;
 46 
 47             case E_STRICT :
 48                 $level = "info";
 49                 $icon = 'info-circle';
 50                 $title = "PHP Strict";
 51                 App::logger()->notice($str);
 52                 break;
 53 
 54             case E_DEPRECATED :
 55             case E_USER_DEPRECATED :
 56                 $level = "info";
 57                 $icon = 'info-circle';
 58                 $title = "PHP Deprecated";
 59                 App::logger()->notice($str);
 60                 break;
 61 
 62             case E_USER_WARNING :
 63             case E_WARNING :
 64                 $level = "warning";
 65                 $icon = "exclamation-triangle";
 66                 $title = "PHP Warning";
 67                 App::logger()->warning($str);
 68                 break;
 69 
 70             default:
 71                 $level = "danger";
 72                 $icon = "exclamation-circle";
 73                 $title = "PHP Error";
 74                 App::logger()->error($str);
 75                 break;
 76         }
 77 
 78         $param = array(
 79         'level' => $level,
 80         'icon' => $icon,
 81         'title' => $title,
 82         'message' => $str,
 83         'trace' => array(
 84         array('file' => $file, 'line' => $line)
 85         )
 86         );
 87 
 88         if(!App::response()->getContentType() === "json") {
 89             App::response()->setBody($param);
 90             throw new AppStopException();
 91         }
 92         else{
 93             echo View::make(Theme::getSelected()->getView('error.tpl'), $param);
 94         }
 95     }
 96 
 97 
 98     /**
 99      * Handle an non catched exception
100      *
101      * @param Exception $e The throwed exception
102      */
103     public function exception($e){
104         $param = array(
105         'level' => 'danger',
106         'icon' => 'excalamation-circle',
107         'title' => get_class($e),
108         'message' => $e->getMessage(),
109         'trace' => $e->getTrace()
110         );
111 
112         App::logger()->error($e->getMessage());
113         if(App::response()->getContentType() === "json") {
114             App::response()->setBody($param);
115         }
116         else{
117             App::response()->setBody(View::make(Theme::getSelected()->getView('error.tpl'), $param));
118             App::response()->end();
119         }
120     }
121 
122     /**
123      * Handle fatal errors
124      */
125     public function fatalError(){
126         $error = error_get_last();
127 
128         if($error !== null) {
129             $errno   = $error["type"];
130             $errfile = $error["file"];
131             $errline = $error["line"];
132             $errstr  = $error["message"];
133 
134             $this->error($errno, $errstr, $errfile, $errline, array());
135         }
136     }
137 
138 }
139 
Hawk - PHP documentation API documentation generated by ApiGen