<?


/**
 * $Id: Exception.class.php 863 2008-07-08 08:05:50Z pawy $
 * Obsluga wyjatkow jadra
 *
 */
class CoreException extends Exception { 
  /**
   * Backtrace
   *
   * @var array
   */
  public $backtrace;
  /**
   * Konstruktor
   *
   * @param string $message
   * @param integer $code
   */
  public function __construct($message=false, $code=false) {
    $this->message = $message;
    $this->backtrace = debug_backtrace();
  }

  public function  __toString() {
      $out = '<br />';
      $c = count($this->backtrace);
      foreach($this->backtrace as $line) {
          $out .= '<b>[ #'. $c.' ]</b><br /> ';
          $out .= '<b>[ method ]</b>' . $line['function'] . '()<br /><b>[ file ]</b> ' . $line['file']  . ' (line: ' . $line['line'] .')<br /><br />';
          $c--;
      }
      $out .= '<br />';
      return $out;
  }
}
/**
 * Obsluga wyjatkow plikowych
 *
 */
class FileException extends CoreException { 
  /**
   * Backtrace
   *
   * @var array
   */
  public $backtrace;
  /**
   * Konstruktor
   *
   * @param string $message
   * @param integer $code
   */
  public function __construct($message=false, $code=false) {
    $this->message = $message;
    $this->backtrace = debug_backtrace();
  }
}

/**
 * Obsluga wyjatkow mysql
 *
 */
class MysqlException extends FileException { 
  /**
   * Backtrace
   *
   * @var array
   */
  public $backtrace;
  /**
   * Konstruktor
   *
   * @param string $message
   * @param integer $code
   */
  public function __construct($message=false, $code=false) {
    if(!$message) {
      $this->message = mysql_error();
    }
    else
      $this->message = $message;
      
    if(!$code) {
      $this->code = mysqli_errno(1);
    }
    else
      $this->code = $code;
      
    $this->backtrace = debug_backtrace();
   
  }

}

/**
 * Obsluga wyjatkow autoryzacji
 *
 */
class AuthException extends MysqlException { 
  /**
   * Backtrace
   *
   * @var array
   */
  public $backtrace;
  /**
   * Konstruktor
   *
   * @param string $message
   * @param integer $code
   */
  public function __construct($message=false, $code=false) {
    
    $this->backtrace = debug_backtrace();
  }
  
}
/**
 * Obsluga wyjatkow uzytkownika
 *
 */
class UserException extends AuthException { 
  /**
   * Backtrace
   *
   * @var array
   */
  public $backtrace;
  /**
   * Konstruktor
   *
   * @param string $message
   * @param integer $code
   */
  public function __construct($message=false, $code=false) {
    $this->message = $message;
    $this->backtrace = debug_backtrace();
  }
}

/**
 * Wyjatek ApiException.
 *
 * @author WP
 */
class ApiException extends Exception {
}


/**
 * Wyjatek SecurityException.
 *
 * @author WP
 */
class SecurityException extends ApiException {
}


?>