This commit is contained in:
Ulf Gebhardt 2016-06-10 10:28:58 +02:00
parent 1d284dad3c
commit f2d7596be5
28 changed files with 513 additions and 75 deletions

View File

@ -1,12 +1,26 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Error handler Class provided by System to derive your own loghandlers from.
*/
class error_handler { class error_handler {
//Error Mask E_ALL, E_NOTICE ... /**
public static function MASK(){ * Call function to handle exceptions
throw new \RuntimeException("Implement this");} *
//Errorhandler * @param \Exception $E Thrown Execption to be handled
public static function CALL(\Exception $E, $thrown){ * @param bool $thrown Was the Exception thrown?
throw new \RuntimeException("Implement this");} * @return bool Returns true or false.
*/
public static function CALL(\Exception $E, $thrown){}
} }

View File

@ -1,21 +1,34 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; 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. * Error handler Class provided by System to log to the database.
class error_handler_dbwriter extends \SYSTEM\LOG\error_handler { * Register this before every other handler, cuz this will need to handle every single error.
*/
class error_handler_dbwriter extends \SYSTEM\LOG\error_handler {
/**
* Call function to handle exceptions
*
* @param \Exception $E Thrown Execption to be handled
* @param bool $thrown Was the Exception thrown?
* @return bool Returns true or false.
*/
public static function CALL(\Exception $E, $thrown){ public static function CALL(\Exception $E, $thrown){
try{ try{
if(\property_exists(get_class($E), 'logged') && $E->logged){ if(\property_exists(get_class($E), 'logged') && $E->logged){
return false;} //alrdy logged(this prevents proper thrown value for every system exception) return false;} //alrdy logged(this prevents proper thrown value for every system exception)
$result = \SYSTEM\SQL\SYS_LOG_INSERT::QI( /*array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(), $result = \SYSTEM\SQL\SYS_LOG_INSERT::QI(array(
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5), get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
$_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST),
array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null,
array_key_exists('HTTP_USER_AGENT',$_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null,
($user = \SYSTEM\SECURITY\security::getUser()) ? $user->id : null, $thrown ? 1 : 0),*/
array( get_class($E), $E->getMessage(), $E->getCode(), $E->getFile(), $E->getLine(), $E->getTraceAsString(),
getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5), getenv('REMOTE_ADDR'),round(microtime(true) - \SYSTEM\time::getStartTime(),5),
$_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST), $_SERVER["SERVER_NAME"],$_SERVER["SERVER_PORT"],$_SERVER['REQUEST_URI'], serialize($_POST),
array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null, array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : null,

View File

@ -1,15 +1,34 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Error handler Class provided by System to return the Error as JSON.
* Register this Handler as last one
*/
class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler { class error_handler_jsonoutput extends \SYSTEM\LOG\error_handler {
//Only those who die! /**
* Call function to handle exceptions
*
* @param \Exception $E Thrown Execption to be handled
* @param bool $thrown Was the Exception thrown?
* @return bool Returns true or false.
*/
public static function CALL(\Exception $E, $thrown){ public static function CALL(\Exception $E, $thrown){
if($thrown){ if($thrown){
try{ try{
echo \SYSTEM\LOG\JsonResult::error($E); echo \SYSTEM\LOG\JsonResult::error($E);
} catch (\Exception $E){} //Error -> Ignore } catch (\Exception $E){} //Error -> Ignore
return die(); //die is required cuz else some fatals cant be catched properly return true;
} }
} }
} }

View File

@ -1,5 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class COUNTER extends \SYSTEM\LOG\INFO {} /**
* Counter Log Class provided by System to count calls to the Site.
*/
class COUNTER extends \SYSTEM\LOG\INFO {}

View File

@ -1,5 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class CRON extends \SYSTEM\LOG\INFO{} /**
* Cron Log Class provided by System for Cron Messages.
*/
class CRON extends \SYSTEM\LOG\INFO{}

View File

@ -1,4 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Deprecated Log Class provided by System for marking code as Deprecated.
*/
class DEPRECATED extends \SYSTEM\LOG\TODO {} class DEPRECATED extends \SYSTEM\LOG\TODO {}

View File

@ -1,4 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Error Log Class provided by System for all kinds of Errors.
*/
class ERROR extends \SYSTEM\LOG\TODO {} class ERROR extends \SYSTEM\LOG\TODO {}

View File

@ -1,4 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Error Exception Log Class provided by System for Errors Exceptions.
*/
class ERROR_EXCEPTION extends \SYSTEM\LOG\SYSTEM_ERROR_EXCEPTION {} class ERROR_EXCEPTION extends \SYSTEM\LOG\SYSTEM_ERROR_EXCEPTION {}

View File

@ -1,5 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class INFO extends \SYSTEM\LOG\SYSTEM_EXCEPTION {} /**
* Info Log Class provided by System for logging Infos.
*/
class INFO extends \SYSTEM\LOG\SYSTEM_EXCEPTION {}

View File

@ -1,4 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Shutdown Exception Class provided by System for logging Shutdown Exceptions.
*/
class SHUTDOWN_EXCEPTION extends \SYSTEM\LOG\SYSTEM_ERROR_EXCEPTION {} class SHUTDOWN_EXCEPTION extends \SYSTEM\LOG\SYSTEM_ERROR_EXCEPTION {}

View File

@ -1,11 +1,35 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* System Exception Class provided by System for logging all kinds of System Exceptions.
* All other error exception Classes are derived from this.
*/
class SYSTEM_ERROR_EXCEPTION extends \ErrorException { class SYSTEM_ERROR_EXCEPTION extends \ErrorException {
/** bool Variable to store if the Exception was logged already */
public $logged = false; public $logged = false;
/**
* Construct the Error
*
* @param string $message Error Message
* @param int $code Error Code
* @param int $severity Severity of the Error
* @param string $filename Filename where the Error occurred
* @param int $lineno Line number where the Error occurred
* @param \Exception $previous Previous Error leading to this one.
*/
public function __construct($message = "", $code = 1, $severity = 0, $filename = "", $lineno = 0, $previous = NULL){ public function __construct($message = "", $code = 1, $severity = 0, $filename = "", $lineno = 0, $previous = NULL){
parent::__construct($message, $code, $severity, $filename, $lineno, $previous); parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
\SYSTEM\LOG\log::__exception_handler($this,false); \SYSTEM\LOG\log::__exception_handler($this,false);
} }
} }

View File

@ -1,12 +1,35 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* System Exception Class provided by System for logging all kinds of System Exceptions.
* All other log Classes are derived from this.
*/
class SYSTEM_EXCEPTION extends \Exception { class SYSTEM_EXCEPTION extends \Exception {
/** bool Variable to store if the Exception was logged already */
public $logged = false; public $logged = false;
/** bool Variable to store if the Exceptions was logged as Todo */
public $todo_logged = false; public $todo_logged = false;
/**
* Construct the Error
*
* @param string $message Error Message
* @param int $code Error Code
* @param \Exception $previous Previous Error leading to this one.
*/
public function __construct($message = "", $code = 1, $previous = NULL){ public function __construct($message = "", $code = 1, $previous = NULL){
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
\SYSTEM\LOG\log::__exception_handler($this,false); \SYSTEM\LOG\log::__exception_handler($this,false);
} }
} }

View File

@ -1,7 +1,27 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Todo Class provided by System for logging todos.
*/
class TODO extends \SYSTEM\LOG\SYSTEM_EXCEPTION { class TODO extends \SYSTEM\LOG\SYSTEM_EXCEPTION {
/**
* Construct the Error and logs it to the Todo aswell
*
* @param string $message Error Message
* @param int $code Error Code
* @param \Exception $previous Previous Error leading to this one.
*/
public function __construct($message = "", $code = 1, $previous = NULL){ public function __construct($message = "", $code = 1, $previous = NULL){
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
\SYSTEM\SAI\saimod_sys_todo::exception($this,false);} \SYSTEM\SAI\saimod_sys_todo::exception($this,false);}

View File

@ -1,13 +1,33 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Translateable Error Class provided by System for serving Multilanguage Errors from Database.
*/
class TranslatableError extends \SYSTEM\LOG\ERROR { class TranslatableError extends \SYSTEM\LOG\ERROR {
/**
* Construct the Error and logs it. Requests the Error String from db based on a given string_id.
* Result can varry upon callers locale settings.
*
* @param string $string_id String Id from Text Database
* @param int $code Error Code
* @param \Exception $previous Previous Error leading to this one.
* @param string $locale Language of the Error to be thrown. Can be Null to use user's settings
*/
public function __construct($string_id, $code = 0, $previous = NULL , $locale = NULL){ public function __construct($string_id, $code = 0, $previous = NULL , $locale = NULL){
$message = \SYSTEM\PAGE\text::get($string_id, $locale); $message = \SYSTEM\PAGE\text::get($string_id, $locale);
if(!$message){ if(!$message){
throw new \SYSTEM\LOG\ERROR("Could not retrive Errortranslation: ".$string_id);} throw new \SYSTEM\LOG\ERROR("Could not retrive Errortranslation: ".$string_id);}
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
} }

View File

@ -1,4 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
/**
* Warning Class provided by System for logging Warnings.
*/
class WARNING extends \SYSTEM\LOG\TODO {} class WARNING extends \SYSTEM\LOG\TODO {}

View File

@ -1,2 +1,16 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* Deprecated Log Class provided by System for marking code as Deprecated.
*/
class DEPRECATED extends \SYSTEM\LOG\DEPRECATED {} class DEPRECATED extends \SYSTEM\LOG\DEPRECATED {}

View File

@ -1,2 +1,16 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* Error Log Class provided by System for all kinds of Errors.
*/
class ERROR extends \SYSTEM\LOG\ERROR {} class ERROR extends \SYSTEM\LOG\ERROR {}

View File

@ -1,3 +1,17 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* Info Log Class provided by System for logging Infos.
*/
class INFO extends \SYSTEM\LOG\INFO {} class INFO extends \SYSTEM\LOG\INFO {}

View File

@ -1,2 +1,16 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* Todo Class provided by System for logging todos.
*/
class TODO extends \SYSTEM\LOG\TODO {} class TODO extends \SYSTEM\LOG\TODO {}

View File

@ -1,2 +1,16 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* Warning Class provided by System for logging Warnings.
*/
class WARNING extends \SYSTEM\LOG\WARNING {} class WARNING extends \SYSTEM\LOG\WARNING {}

View File

@ -1,15 +1,32 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
//ini_set('error_prepend_string', '{querytime: 0.0, status: false, result: { class: "FatalError",message: "'); /**
//ini_set('error_append_string', '", code: 1, file: "unknown", line: 0, trace: }}'); * Log Class provided by System to manage log handlers.
*/
class log { class log {
/** string Variable to store hander function call name */
const HANDLER_FUNC_CALL = 'CALL'; const HANDLER_FUNC_CALL = 'CALL';
/** array Variable to store all registred log handlers */
private static $handlers = array(); private static $handlers = array();
//$handler = string with classname /**
* Register a Log Handler
*
* @param class $handler Classname of the handler to be registered
* @return null Returns null.
*/
public static function registerHandler($handler){ public static function registerHandler($handler){
if( !class_exists($handler) || if( !class_exists($handler) ||
!\method_exists($handler,self::HANDLER_FUNC_CALL)){ !\method_exists($handler,self::HANDLER_FUNC_CALL)){
@ -22,24 +39,60 @@ class log {
//ob_start ('\SYSTEM\LOG\log::__fatal_error_handler'); //ob_start ('\SYSTEM\LOG\log::__fatal_error_handler');
} }
/**
* Call handlers function upon error
*
* @param \Exception $E Thrown Execption to be handled
* @param bool $thrown Was the Exception thrown?
* @return bool Returns true or false.
*/
private static function call_handlers(\Exception $E, $thrown = true){ private static function call_handlers(\Exception $E, $thrown = true){
foreach(self::$handlers as $handler){ foreach(self::$handlers as $handler){
if( \call_user_func_array(array($handler,self::HANDLER_FUNC_CALL),array($E, $thrown))){ if( \call_user_func_array(array($handler,self::HANDLER_FUNC_CALL),array($E, $thrown))){
return true;}} return true;}}
return false; return false;}
}
/**
* Exception Handler for System-log handling
*
* @param \Exception $E Thrown Execption to be handled
* @param bool $thrown Was the Exception thrown?
* @return bool Returns true or false depending on thrown
*/
public static function __exception_handler(\Exception $E, $thrown = true){ public static function __exception_handler(\Exception $E, $thrown = true){
return self::call_handlers($E, $thrown) && $thrown;} return self::call_handlers($E, $thrown) && $thrown;}
/**
* Error Handler for System-log handling
*
* @param int $code Errorcode
* @param string $message Error Message
* @param string $file Error File
* @param string $line Error File-Line
* @param bool $thrown Was the Error thrown?
* @return bool Returns true or false
*/
public static function __error_handler($code, $message, $file, $line, $thrown = true){ public static function __error_handler($code, $message, $file, $line, $thrown = true){
return self::call_handlers(new \SYSTEM\LOG\ERROR_EXCEPTION($message, 1, $code, $file, $line) ,$thrown);} return self::call_handlers(new \SYSTEM\LOG\ERROR_EXCEPTION($message, 1, $code, $file, $line) ,$thrown);}
/**
* Shutdown Handler for System-log handling
*
* @param bool $thrown Was the Error thrown?
* @return bool Returns true or false
*/
public static function __shutdown_handler($thrown = true) { 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/ 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 \SYSTEM\LOG\SHUTDOWN_EXCEPTION($error["message"], 1, $error["type"],$error["file"],$error["line"]) ,$thrown);} return self::call_handlers(new \SYSTEM\LOG\SHUTDOWN_EXCEPTION($error["message"], 1, $error["type"],$error["file"],$error["line"]) ,$thrown);}}
}
/**
* Fatal Error Handler for System-log handling
* (unused - experimental)
*
* @param string $bufferContent Website contens before sent to user
* @param bool $thrown Was the Error thrown?
* @return string Returns the buffercontent or an json error.
*/
public static function __fatal_error_handler($bufferContent, $thrown = true){ public static function __fatal_error_handler($bufferContent, $thrown = true){
if( ($error = error_get_last()) !== NULL && !$error['type'] === E_DEPRECATED){ //seams like we cannot call anything but core stuff if( ($error = error_get_last()) !== NULL && !$error['type'] === E_DEPRECATED){ //seams like we cannot call anything but core stuff
$result = array('querytime' => 0, 'status' => false, 'result' => $error); $result = array('querytime' => 0, 'status' => false, 'result' => $error);
@ -48,5 +101,4 @@ class log {
return json_encode($result);} return json_encode($result);}
return $bufferContent; return $bufferContent;
} }
} }

View File

@ -1,5 +1,19 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\SQL
*/
namespace SYSTEM\SQL; namespace SYSTEM\SQL;
/**
* QQ to delete a log entry by id
*/
class SYS_LOG_DEL extends \SYSTEM\DB\QP { class SYS_LOG_DEL extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();} public static function get_class(){return \get_class();}
public static function pgsql(){return public static function pgsql(){return

View File

@ -1,5 +1,19 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\SQL
*/
namespace SYSTEM\SQL; namespace SYSTEM\SQL;
/**
* QQ to insert a new log entry
*/
class SYS_LOG_INSERT extends \SYSTEM\DB\QP { class SYS_LOG_INSERT extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();} public static function get_class(){return \get_class();}
public static function pgsql(){return public static function pgsql(){return

View File

@ -1,5 +1,19 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\SQL
*/
namespace SYSTEM\SQL; namespace SYSTEM\SQL;
/**
* QQ to find all long entries for this month, limited by 10000
*/
class SYS_LOG_MONTH extends \SYSTEM\DB\QP { class SYS_LOG_MONTH extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();} public static function get_class(){return \get_class();}
public static function pgsql(){return public static function pgsql(){return

View File

@ -1,5 +1,19 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\SQL
*/
namespace SYSTEM\SQL; namespace SYSTEM\SQL;
/**
* QQ to find the month of the oldest log entry
*/
class SYS_LOG_OLDEST extends \SYSTEM\DB\QQ { class SYS_LOG_OLDEST extends \SYSTEM\DB\QQ {
public static function get_class(){return \get_class();} public static function get_class(){return \get_class();}
public static function pgsql(){return public static function pgsql(){return

View File

@ -1,15 +0,0 @@
<?php
namespace SYSTEM\LOG;
class AbstractResult {
//Returns the result as a string
public static function toString($json_array, $status , $start_time){
throw new RuntimeException("Unimplemented");}
//Return Exception as string
public static function error(\Exception $e){
throw new RuntimeException("Unimplemented");}
//Returns OK status
public static function ok(){
throw new RuntimeException("Unimplemented");}
}

View File

@ -1,14 +1,29 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
namespace SYSTEM\LOG; namespace SYSTEM\LOG;
class JsonResult extends \SYSTEM\LOG\AbstractResult { /**
* JsonResult Class provided by System to return Data as JSON or MSGPACK.
const JSONRESULT_OK = true; */
const JSONRESULT_ERROR = false; class JsonResult{
/**
public static function toString($json_array, $status = self::JSONRESULT_OK, $start_time = NULL){ * Retun JsonResult with data given by array
*
* @param array $json_array Data which should be included in the JSOn Result.
* @param bool $status true or false depending on success
* @param int $start_time To calculate Querytime - if Null System time is used.
* @return string Returns json string.
*/
public static function toString($json_array, $status = true, $start_time = NULL){
if($start_time == NULL){ if($start_time == NULL){
$start_time = \SYSTEM\time::getStartTime();} $start_time = \SYSTEM\time::getStartTime();}
@ -34,23 +49,36 @@ class JsonResult extends \SYSTEM\LOG\AbstractResult {
} }
} }
//Return Exception as string /**
* Retun JsonResult for given Exception
*
* @param \Exception $e Exception to be convered.
* @return string Returns json string.
*/
public static function error(\Exception $e){ public static function error(\Exception $e){
$error = array(); $error = array();
$error['class'] = get_class($e); $error['class'] = get_class($e);
$error['message'] = $e->getMessage(); $error['message'] = $e->getMessage();
$error['code'] = $e->getCode(); $error['code'] = $e->getCode();
$error['file'] = $e->getFile(); $error['file'] = $e->getFile();
$error['line'] = $e->getLine(); $error['line'] = $e->getLine();
$error['trace'] = array_slice(explode('#', $e->getTraceAsString()), 1, -1); $error['trace'] = array_slice(explode('#', $e->getTraceAsString()), 1, -1);
return self::toString($error, false);
return self::toString($error, self::JSONRESULT_ERROR);
} }
//Returns OK status /**
* Retun JsonResult with success status
*
* @return string Returns json string.
*/
public static function ok(){ public static function ok(){
return self::toString(NULL);} return self::toString(NULL);}
/**
* Retun JsonResult with failure status
*
* @return string Returns json string.
*/
public static function fail(){ public static function fail(){
return self::toString(NULL,self::JSONRESULT_ERROR);} return self::toString(NULL,false);}
} }

View File

@ -1,3 +1,16 @@
<?php <?php
/**
* System - PHP Framework
*
* PHP Version 5.6
*
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link https://github.com/webcraftmedia/system
* @package SYSTEM\LOG
*/
/**
* JsonResult Class provided by System to return Data as JSON or MSGPACK.
*/
class JsonResult extends \SYSTEM\LOG\JsonResult {} class JsonResult extends \SYSTEM\LOG\JsonResult {}