Added som good classes
This commit is contained in:
parent
20496a4be0
commit
0f5bfbdba9
3 changed files with 147 additions and 0 deletions
90
class/error.php
Normal file
90
class/error.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
require_once("info.php");
|
||||
|
||||
/*
|
||||
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
|
||||
|
||||
Value Constant Description
|
||||
1 E_ERROR (integer) 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.
|
||||
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.
|
||||
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.
|
||||
8 E_NOTICE (integer) 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.
|
||||
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
|
||||
32 E_CORE_WARNING (integer) 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.
|
||||
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
|
||||
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
|
||||
|
||||
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
|
||||
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
|
||||
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
|
||||
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
|
||||
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, 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.
|
||||
8191 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT in PHP < 6.
|
||||
|
||||
HTML
|
||||
<div id="info" style="border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;">
|
||||
<center>{'message'}</center>
|
||||
</div>
|
||||
*/
|
||||
|
||||
$errors = array();
|
||||
set_error_handler("errorHandler");
|
||||
register_shutdown_function("printErrors");
|
||||
|
||||
// error handler function
|
||||
function errorHandler($errno, $errstr, $errfile, $errline){
|
||||
GLOBAL $template,$language,$errors;
|
||||
$info = new Info();
|
||||
switch ($errno) {
|
||||
case E_ERROR:
|
||||
case E_USER_ERROR:
|
||||
$err = buildError($language["error"],$errno, $errstr, $errfile, $errline);
|
||||
$errors[] = $info->buildMessage($err,"error");
|
||||
dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
|
||||
break;
|
||||
case E_WARNING:
|
||||
case E_USER_WARNING:
|
||||
$err = buildError($language["warning"],$errno, $errstr, $errfile, $errline);
|
||||
$errors[] = $info->buildMessage($err,"warning");
|
||||
dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
|
||||
break;
|
||||
case E_NOTICE:
|
||||
case E_USER_NOTICE:
|
||||
//$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
|
||||
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
|
||||
break;
|
||||
default:
|
||||
$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
|
||||
$errors[] = $info->buildMessage($err,"error");
|
||||
dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
|
||||
break;
|
||||
}
|
||||
/* Don't execute PHP internal error handler */
|
||||
return true;
|
||||
}
|
||||
|
||||
function buildError($errhead,$errno, $errstr, $errfile, $errline){
|
||||
GLOBAL $config;
|
||||
//[$errno]
|
||||
if($config["debug"])
|
||||
$error = "<strong>$errhead:</strong> $errfile($errline)<br /><b>$errstr</b>";
|
||||
else
|
||||
$error = "<strong>$errhead: </strong>$errstr";
|
||||
return $error;
|
||||
}
|
||||
|
||||
function getErrors(){
|
||||
GLOBAL $errors;
|
||||
if(empty($errors)) return "";
|
||||
$temp = "";
|
||||
foreach($errors as $one){
|
||||
$temp .= $one;
|
||||
}
|
||||
$errors = array();
|
||||
return $temp;
|
||||
}
|
||||
|
||||
function printErrors(){
|
||||
echo getErrors();
|
||||
}
|
||||
?>
|
||||
22
class/info.php
Normal file
22
class/info.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
require_once("template.php");
|
||||
|
||||
class Info{
|
||||
var $type = array (
|
||||
"warning" => array("#F0FF69","#FFFB3E"),
|
||||
"error" => array("#FFDDCC","#FF0000"),
|
||||
"info" => array("#9BFB66","#039C00")
|
||||
);
|
||||
|
||||
function buildMessage($msg, $t="warning"){
|
||||
GLOBAL $template;
|
||||
$temp = new Template($template["message"]);
|
||||
$temp->replace_tags(array(
|
||||
"message_color" => $this->type[$t][0],
|
||||
"message_color_border" => $this->type[$t][1],
|
||||
"message" => $msg
|
||||
));
|
||||
return $temp->getOutput();
|
||||
}
|
||||
}
|
||||
?>
|
||||
35
class/template.php
Normal file
35
class/template.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
class Template{
|
||||
var $page;
|
||||
|
||||
function Template($template = "HelloWorld!!!") {
|
||||
$this->page = $template;
|
||||
}
|
||||
|
||||
function replace_tags($tags = array()) {
|
||||
if (sizeof($tags) > 0)
|
||||
foreach ($tags as $tag => $data) {
|
||||
//$data = (file_exists($data)) ? $this->parse($data) : $data;
|
||||
$this->page = str_ireplace("{'" . $tag . "'}", $data, $this->page);//eregi_replace
|
||||
}
|
||||
else
|
||||
die("No tags designated for replacement.");
|
||||
}
|
||||
|
||||
function output() {
|
||||
echo $this->page;
|
||||
}
|
||||
|
||||
function getOutput() {
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
function parse($file) {
|
||||
ob_start();
|
||||
include($file);
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue