Source for file jException.class.php

Documentation is available at jException.class.php

  1. <?php
  2. /**
  3. * @package     jelix
  4. * @subpackage  core
  5. * @author      Laurent Jouanneau
  6. * @contributor Sylvain de Vathaire, Julien Issler
  7. * @copyright   2005-2012 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. /**
  15.  * Jelix Exception
  16.  *
  17.  * It handles locale messages. Message property contains the locale key,
  18.  * and a new property contains the localized message.
  19.  * @package  jelix
  20.  * @subpackage core
  21.  */
  22. class jException extends Exception {
  23.  
  24.     /**
  25.      * the locale key
  26.      * @var string 
  27.      */
  28.     protected $localeKey = '';
  29.  
  30.     /**
  31.      * parameters for the locale key
  32.      */
  33.     protected $localeParams = array();
  34.  
  35.     /**
  36.      * @param string $localekey a locale key
  37.      * @param array $localeParams parameters for the message (for sprintf)
  38.      * @param integer $code error code (can be provided by the localized message)
  39.      * @param string $lang 
  40.      * @param string $charset 
  41.      */
  42.     public function __construct($localekey, $localeParams = array(), $code = 1, $lang = null, $charset = null) {
  43.  
  44.         $this->localeKey = $localekey;
  45.         $this->localeParams = $localeParams;
  46.  
  47.         try{
  48.             $message = jLocale::get($localekey, $localeParams, $lang, $charset);
  49.         }catch(Exception $e){
  50.             $message = $e->getMessage();
  51.         }
  52.         if(preg_match('/^\s*\((\d+)\)(.+)$/m',$message,$m)){
  53.             $code = $m[1];
  54.             $message = $m[2];
  55.         }
  56.         parent::__construct($message, $code);
  57.     }
  58.  
  59.     /**
  60.      * magic function for echo
  61.      * @return string localized message
  62.      */
  63.     /*public function __toString() {
  64.         return $this->localizedMessage;
  65.     }*/
  66.  
  67.     /**
  68.      * getter for the locale parameters
  69.      * @return string 
  70.      */
  71.     public function getLocaleParameters(){
  72.         return $this->localeParams;
  73.     }
  74.  
  75.     /**
  76.      * getter for the locale key
  77.      * @return string 
  78.      */
  79.     public function getLocaleKey(){
  80.         return $this->localeKey;
  81.     }
  82.  
  83. }

Documentation generated on Wed, 04 Jan 2017 22:54:04 +0100 by phpDocumentor 1.4.3