PHP Classes
elePHPant
Icontem

File: gCurl/gksException.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Grigori Kochanov  >  gCurl  >  gCurl/gksException.class.php  >  Download  
File: gCurl/gksException.class.php
Role: Class source
Content type: text/plain
Description: interface for all my exception classes
Class: gCurl
Perform HTTP requests using Curl
Author: By
Last change:
Date: 7 years ago
Size: 1,731 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
 * @desc returns the value of the configuration parameter (from the database)
 */
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
}