Source for file jException.lib.php

Documentation is available at jException.lib.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  core
  5. @author      Laurent Jouanneau
  6. @contributor Sylvain de Vathaire, Julien Issler
  7. @copyright   2005-2010 laurent Jouanneau, 2007 Sylvain de Vathaire
  8. @copyright   2008 Julien Issler
  9. @link        http://www.jelix.org
  10. @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  11. */
  12.  
  13. /**
  14. * Exception handler for the framework.
  15. * Replace the default PHP Exception handler
  16. @param   Exception   $e  the exception object
  17. */
  18. function jExceptionHandler($e){
  19.     global $gJConfig$gJCoord;
  20.  
  21.     $gJCoord->handleError($gJConfig->error_handling['exception'].' EXIT''exception',
  22.                         $e->getCode()$e->getMessage()$e->getFile()$e->getLine()$e->getTrace());
  23. }
  24.  
  25.  
  26. /**
  27.  * Jelix Exception
  28.  *
  29.  * It handles locale messages. Message property contains the locale key,
  30.  * and a new property contains the localized message.
  31.  * @package  jelix
  32.  * @subpackage core
  33.  */
  34. class jException extends Exception {
  35.  
  36.     /**
  37.      * the locale key
  38.      * @var string 
  39.      */
  40.     protected $localeKey = '';
  41.  
  42.     /**
  43.      * parameters for the locale key
  44.      */
  45.     protected $localeParams = array();
  46.  
  47.     /**
  48.      * @param string $localekey a locale key
  49.      * @param array $localeParams parameters for the message (for sprintf)
  50.      * @param integer $code error code (can be provided by the localized message)
  51.      * @param string $lang 
  52.      * @param string $charset 
  53.      */
  54.     public function __construct($localekey$localeParams array()$code 1$lang null$charset null{
  55.  
  56.         $this->localeKey = $localekey;
  57.         $this->localeParams = $localeParams;
  58.  
  59.         try{
  60.             $message jLocale::get($localekey$localeParams$lang$charset);
  61.         }catch(Exception $e){
  62.             $message $e->getMessage();
  63.         }
  64.         if(preg_match('/^\s*\((\d+)\)(.+)$/m',$message,$m)){
  65.             $code $m[1];
  66.             $message $m[2];
  67.         }
  68.         parent::__construct($message$code);
  69.     }
  70.  
  71.     /**
  72.      * magic function for echo
  73.      * @return string localized message
  74.      */
  75.     /*public function __toString() {
  76.         return $this->localizedMessage;
  77.     }*/
  78.  
  79.     /**
  80.      * getter for the locale parameters
  81.      * @return string 
  82.      */
  83.     public function getLocaleParameters(){
  84.         return $this->localeParams;
  85.     }
  86.  
  87.     /**
  88.      * getter for the locale key
  89.      * @return string 
  90.      */
  91.     public function getLocaleKey(){
  92.         return $this->localeKey;
  93.     }
  94.  
  95. }

Documentation generated on Thu, 22 Mar 2012 22:15:27 +0100 by phpDocumentor 1.4.3