PHP Classes

File: gksException.class.php

Recommend this page to a friend!
  Classes of Grigori Kochanov   gksEncrypt   gksException.class.php   Download  
File: gksException.class.php
Role: Class source
Content type: text/plain
Description: my common exceptions interface
Class: gksEncrypt
Encrypt and decrypt data asymmetrically
Author: By
Last change:
Date: 16 years ago
Size: 1,592 bytes
 

Contents

Class file image Download
<?php
/**
 * The interface defines the methods that prepare the log message, HTML-formatted message
 *
 */
interface gksException{
   
/**
     * Prepare the message to write to the log
     *
     * @return string
     */
   
public function getLogMessage();
   
   
/**
     * returns the exception dump prepared for a browser
     *
     * @return string
     */
   
public function getHtmlMessage();
}

/* EXCEPTIONS */
class pException extends Exception implements gksException {

static private
$error_codes;
public
$httpResponceCode=500;
public
$defaultErrorMessage;

/**
 * @param $code int - error code from [lang].errors.php
 */
function __construct($code){
    if (!
self::$error_codes){
       
$errors_file=_Config::$CONFIG_DIR.'/errors.php';
       
self::$error_codes = include($errors_file);
    }
   
$this->defaultErrorMessage=self::$error_codes[1];

   
key_exists($code, self::$error_codes) || $code=1;
   
$message=self::$error_codes[$code];
   
parent::__construct($message, $code);
}

/**
 * Create the message to write to the log
 *
 * @return string
 */
function getLogMessage(){
   
$log_string='Exception: '.$this->getMessage().' ('.$this->getCode().')'."\n".
       
'line '.$this->getLine().' file '.$this->getFile()."\n".$this->getTraceAsString()."\n";
    return
$log_string;
}

public function
getHtmlMessage(){
   
$message = 'Exception: '. nl2br ($this->getMessage());
   
$trace = 'TRACE: <br />'. nl2br ($this->getTraceAsString());
    return
'<p style="font-weignt: bold; padding: 10px;">'."\n".$message."<br />\n".$trace."</p>\n";
}
//class end
}