diff --git a/log/LOG.php b/log/LOG.php deleted file mode 100644 index 4f791f1..0000000 --- a/log/LOG.php +++ /dev/null @@ -1,96 +0,0 @@ -handlers[] = $handler; - - set_error_handler('\SYSTEM\LOG\LOG::__error_handler'); - set_exception_handler('\SYSTEM\LOG\LOG::__exception_handler'); - } - - private function call_handlers(\Exception $E, $errno, $thrown = false){ - foreach($this->handlers as $handler){ - if( ((call_user_func(array($handler,'MASK')) & $errno)) && - call_user_func_array(array($handler,'CALL'),array($E,$errno, $thrown))){ - return true; - } - } - return false; - } - -//Static - //Exceptions - public static function __exception_handler(\Exception $E, $thrown = true){ - if($E instanceof \SYSTEM\LOG\ERROR) { return self::LOG_EXCEPTION($E, E_USER_ERROR, $thrown);} //Dies - if($E instanceof \SYSTEM\LOG\WARNING) { return self::LOG_EXCEPTION($E, E_USER_WARNING, $thrown);} //Continues - if($E instanceof \SYSTEM\LOG\INFO) { return self::LOG_EXCEPTION($E, E_NOTICE, $thrown);} //Continues - if($E instanceof \SYSTEM\LOG\DEPRECATED){ return self::LOG_EXCEPTION($E, E_USER_DEPRECATED, $thrown);} //Continues - self::LOG_EXCEPTION($E, E_USER_ERROR, $thrown); //Dies - } - - //Triggers error, if not handled by registered Handlers(double check -> but only this way we can keep the original Exception class) - protected static function LOG_EXCEPTION(\Exception $E,$errno = E_USER_ERROR, $thrown = false){ - self::__error_handler_e($E, $errno, $thrown);} - - //Errors - public static function __error_handler($errno, $errstr, $errfile, $errline){ - $e = new \SYSTEM\LOG\ERROR($errstr,$errno); - return self::__error_handler_e($e ,$errno, true);} - public static function __error_handler_e(\Exception $E, $errno, $thrown){ - switch ($errno) { - //Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. - case E_ERROR: return self::_DIE($E,$errno,true); - //Run-time warnings (non-fatal errors). Execution of the script is not halted. - case E_WARNING: return self::_CONTINUE($E,$errno,true); - //Compile-time parse errors. Parse errors should only be generated by the parser. - case E_PARSE: return self::_DIE($E,$errno,true); - //Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. - case E_NOTICE: return self::_CONTINUE($E,$errno,false | $thrown); - //Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. - case E_CORE_ERROR: return self::_DIE($E,$errno,true); - //Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP. - case E_CORE_WARNING: return self::_CONTINUE($E,$errno,true); - //Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. - case E_COMPILE_ERROR: return self::_DIE($E,$errno,true); - //Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. - case E_COMPILE_WARNING: return self::_CONTINUE($E,$errno,true); - //User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). - case E_USER_ERROR: return self::_DIE($E,$errno,false | $thrown); - //User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). - case E_USER_WARNING: return self::_CONTINUE($E,$errno,false | $thrown); - //Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. Since PHP 5 but not included in E_ALL until PHP 5.4.0 rated in PHP code by using the PHP function trigger_error(). - case E_STRICT: return self::_CONTINUE($E,$errno,true); - //Catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. Since PHP 5.2.0 - case E_RECOVERABLE_ERROR: return self::_CONTINUE($E,$errno,true); - //Run-time notices. Enable this to receive warnings about code that will not work in future versions. Since PHP 5.3.0 - case E_DEPRECATED: return self::_CONTINUE($E,$errno,true); - //User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error(). Since PHP 5.3.0 - case E_USER_DEPRECATED: return self::_CONTINUE($E,$errno,false | $thrown); - default: return false; //Not handled Error use std php handler - } - } - - private static function _DIE(\Exception $E, $errno, $thrown = false){ - if(self::getInstance()->call_handlers($E, $errno, $thrown)){die();}} - private static function _CONTINUE(\Exception $E, $errno, $thrown = false){ - return self::getInstance()->call_handlers($E, $errno, $thrown);} -} \ No newline at end of file diff --git a/log/error_handler/error_handler.php b/log/error_handler/error_handler.php index 61e179e..093707c 100644 --- a/log/error_handler/error_handler.php +++ b/log/error_handler/error_handler.php @@ -7,6 +7,6 @@ class error_handler { public static function MASK(){ throw new \RuntimeException("Implement this");} //Errorhandler - public static function CALL(\Exception $E, $errno, $thrown){ + public static function CALL(\Exception $E, $thrown){ throw new \RuntimeException("Implement this");} } \ No newline at end of file diff --git a/log/error_handler/error_handler_dbwriter.php b/log/error_handler/error_handler_dbwriter.php index 6551f97..2b47a2e 100644 --- a/log/error_handler/error_handler_dbwriter.php +++ b/log/error_handler/error_handler_dbwriter.php @@ -5,8 +5,11 @@ namespace SYSTEM\LOG; //Register this before every other handler, cuz this will need to handle every single error. //And only the first ErrorHandler will be called if he returns true in CALL. class error_handler_dbwriter extends \SYSTEM\LOG\error_handler { - public static function CALL(\Exception $E, $errno, $thrown){ - try{ + public static function CALL(\Exception $E, $thrown){ + try{ + if(\property_exists(get_class($E), 'logged') && $E->logged){ + return false;} //alrdy logged + if(\SYSTEM\system::isSystemDbInfoPG()){ $con = new \SYSTEM\DB\Connection(\SYSTEM\system::getSystemDBInfo()); $con->prepare( 'sysLogStmt', 'INSERT INTO system.sys_log '. @@ -22,6 +25,9 @@ class error_handler_dbwriter extends \SYSTEM\LOG\error_handler { array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5),microtime(true))); } + + if(\property_exists(get_class($E), 'logged')){ + $E->logged = true;} //we just did log } catch (\Exception $E){} //Error -> Ignore return false; //We just log and do not handle the error! diff --git a/log/error_handler/error_handler_jsonoutput.php b/log/error_handler/error_handler_jsonoutput.php index dbc4ed9..d2af125 100644 --- a/log/error_handler/error_handler_jsonoutput.php +++ b/log/error_handler/error_handler_jsonoutput.php @@ -5,11 +5,12 @@ namespace SYSTEM\LOG; class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler { //Only those who die! public static function MASK(){ return \E_ALL;} //\E_ERROR | \E_USER_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR; } - public static function CALL(\Exception $E, $errno, $thrown){ - if($thrown){ - //TODO move jsonresult into system - echo \SYSTEM\LOG\JsonResult::error($E); - die(); //we can have only one json result per page call else -> multiple headers are sent + public static function CALL(\Exception $E, $thrown){ + if($thrown){ + try{ + echo \SYSTEM\LOG\JsonResult::error($E); + } catch (\Exception $E){} //Error -> Ignore + return true; } } } \ No newline at end of file diff --git a/log/exceptions/DEPRECATED.php b/log/exceptions/DEPRECATED.php index d6bc9e7..5434c71 100644 --- a/log/exceptions/DEPRECATED.php +++ b/log/exceptions/DEPRECATED.php @@ -1,10 +1,4 @@ getCode())) && + \call_user_func_array(array($handler,self::HANDLER_FUNC_CALL),array($E, $thrown))){ + return true;} + } + return false; + } + + public static function __exception_handler(\Exception $E, $thrown = true){ + return self::call_handlers($E, $thrown) && $thrown;} + + public static function __error_handler($code, $message, $file, $line, $thrown = true){ + return self::call_handlers(new \ErrorException($message, 1, $code, $file, $line) ,$thrown);} + + public static function __shutdown_handler($thrown = true) { + if( ($error = error_get_last()) !== NULL && !$error['type'] === E_DEPRECATED) { //http://www.dreamincode.net/forums/topic/284506-having-trouble-supressing-magic-quotes-gpc-fatal-errors/ + return self::call_handlers(new \ErrorException($error["message"], 1, $error["type"],$error["file"],$error["line"]) ,$thrown);} + } +} + diff --git a/log/register_errorhandler_dbwriter.php b/log/register_errorhandler_dbwriter.php index 7bcbd69..2ec74c8 100644 --- a/log/register_errorhandler_dbwriter.php +++ b/log/register_errorhandler_dbwriter.php @@ -1,2 +1,2 @@ registerHandler('\SYSTEM\LOG\error_handler_dbwriter'); \ No newline at end of file +\SYSTEM\LOG\log::registerHandler('\SYSTEM\LOG\error_handler_dbwriter'); \ No newline at end of file diff --git a/log/register_errorhandler_jsonoutput.php b/log/register_errorhandler_jsonoutput.php index 22c32bd..7479dfd 100644 --- a/log/register_errorhandler_jsonoutput.php +++ b/log/register_errorhandler_jsonoutput.php @@ -1,2 +1,2 @@ registerHandler('\SYSTEM\LOG\error_handler_jsonoutput'); \ No newline at end of file +\SYSTEM\LOG\log::registerHandler('\SYSTEM\LOG\error_handler_jsonoutput'); \ No newline at end of file diff --git a/system/HEADER.php b/system/HEADER.php index daf5407..7bacb98 100644 --- a/system/HEADER.php +++ b/system/HEADER.php @@ -1,14 +1,22 @@ '; const C_SUBPATH = ''; abstract class PATH { - abstract static public function getPath(); + static public function getPath(){ + throw new \RuntimeException("Not Implemented");} } class PROOT extends PATH {