Changeset 457

Show
Ignore:
Timestamp:
06/15/07 17:21:58 (2 years ago)
Author:
laurentj
Message:

changed API of jException : getMessage now returns the localized message instead of the locale key, there isn't anymore localizedMessage property, localeParams property, and getLocaleMessage method. New methods : getLocaleKey and getLocaleParameters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/core/jException.lib.php

    r334 r457  
    1818    global $gJConfig, $gJCoord; 
    1919 
    20     if($exception instanceof jException){ 
    21         $msg = $exception->getLocaleMessage(); 
    22     }else{ 
    23         $msg = $exception->getMessage(); 
    24     } 
     20    $msg = $exception->getMessage(); 
    2521 
    2622    $conf = $gJConfig->error_handling; 
     
    2824 
    2925    $doecho=true; 
     26 
    3027    if($gJCoord->request == null){ 
     28 
    3129        $msg = 'JELIX PANIC ! Error during initialization !! '.$msg; 
    3230        $doecho = false; 
     31 
    3332    }elseif($gJCoord->response == null){ 
     33 
    3434        $ret = $gJCoord->initDefaultResponseOfRequest(); 
    3535        if(is_string($ret)){ 
     
    106106 
    107107    /** 
     108     * the locale key 
     109     * @var string 
     110     */ 
     111    protected $localeKey = ''; 
     112 
     113    /** 
    108114     * parameters for the locale key 
    109115     */ 
    110     public $localeParams = array(); 
    111  
    112     /** 
    113      * the localized message 
    114      * @var string 
    115      */ 
    116     public $localizedMessage = ''; 
     116    protected $localeParams = array(); 
    117117 
    118118    /** 
     
    122122     */ 
    123123    public function __construct($localekey, $localeParams=array(), $code = 1) { 
     124 
     125        $this->localeKey = $localekey; 
     126        $this->localeParams = $localeParams; 
     127 
    124128        try{ 
    125             $this->localizedMessage = jLocale::get($localekey, $localeParams); 
     129            $message = jLocale::get($localekey, $localeParams); 
    126130        }catch(Exception $e){ 
    127             $this->localizedMessage = $e->getMessage(); 
     131            $message = $e->getMessage(); 
    128132        } 
    129         if(preg_match('/^\s*\((\d+)\)(.+)$/',$this->localizedMessage,$m)){ 
     133        if(preg_match('/^\s*\((\d+)\)(.+)$/',$message,$m)){ 
    130134            $code = $m[1]; 
    131             $this->localizedMessage = $m[2]; 
     135            $message = $m[2]; 
    132136        } 
    133         parent::__construct($localekey, $code); 
    134         $this->localeParams=$localeParams; 
     137        parent::__construct($message, $code); 
    135138    } 
    136139 
     
    139142     * @return string localized message 
    140143     */ 
    141     public function __toString() { 
     144    /*public function __toString() { 
    142145        return $this->localizedMessage; 
     146    }*/ 
     147 
     148    /** 
     149     * getter for the locale parameters 
     150     * @return string 
     151     */ 
     152    public function getLocaleParameters(){ 
     153        return $this->localeParams; 
    143154    } 
    144155 
    145156    /** 
    146      * getter for the localized message 
     157     * getter for the locale key 
    147158     * @return string 
    148159     */ 
    149     public function getLocaleMessage(){ 
    150         return $this->localizedMessage
     160    public function getLocaleKey(){ 
     161        return $this->localeKey
    151162    } 
    152163 
  • trunk/lib/jelix/core/jException.lib.php

    r334 r457  
    1818    global $gJConfig, $gJCoord; 
    1919 
    20     if($exception instanceof jException){ 
    21         $msg = $exception->getLocaleMessage(); 
    22     }else{ 
    23         $msg = $exception->getMessage(); 
    24     } 
     20    $msg = $exception->getMessage(); 
    2521 
    2622    $conf = $gJConfig->error_handling; 
     
    2824 
    2925    $doecho=true; 
     26 
    3027    if($gJCoord->request == null){ 
     28 
    3129        $msg = 'JELIX PANIC ! Error during initialization !! '.$msg; 
    3230        $doecho = false; 
     31 
    3332    }elseif($gJCoord->response == null){ 
     33 
    3434        $ret = $gJCoord->initDefaultResponseOfRequest(); 
    3535        if(is_string($ret)){ 
     
    106106 
    107107    /** 
     108     * the locale key 
     109     * @var string 
     110     */ 
     111    protected $localeKey = ''; 
     112 
     113    /** 
    108114     * parameters for the locale key 
    109115     */ 
    110     public $localeParams = array(); 
    111  
    112     /** 
    113      * the localized message 
    114      * @var string 
    115      */ 
    116     public $localizedMessage = ''; 
     116    protected $localeParams = array(); 
    117117 
    118118    /** 
     
    122122     */ 
    123123    public function __construct($localekey, $localeParams=array(), $code = 1) { 
     124 
     125        $this->localeKey = $localekey; 
     126        $this->localeParams = $localeParams; 
     127 
    124128        try{ 
    125             $this->localizedMessage = jLocale::get($localekey, $localeParams); 
     129            $message = jLocale::get($localekey, $localeParams); 
    126130        }catch(Exception $e){ 
    127             $this->localizedMessage = $e->getMessage(); 
     131            $message = $e->getMessage(); 
    128132        } 
    129         if(preg_match('/^\s*\((\d+)\)(.+)$/',$this->localizedMessage,$m)){ 
     133        if(preg_match('/^\s*\((\d+)\)(.+)$/',$message,$m)){ 
    130134            $code = $m[1]; 
    131             $this->localizedMessage = $m[2]; 
     135            $message = $m[2]; 
    132136        } 
    133         parent::__construct($localekey, $code); 
    134         $this->localeParams=$localeParams; 
     137        parent::__construct($message, $code); 
    135138    } 
    136139 
     
    139142     * @return string localized message 
    140143     */ 
    141     public function __toString() { 
     144    /*public function __toString() { 
    142145        return $this->localizedMessage; 
     146    }*/ 
     147 
     148    /** 
     149     * getter for the locale parameters 
     150     * @return string 
     151     */ 
     152    public function getLocaleParameters(){ 
     153        return $this->localeParams; 
    143154    } 
    144155 
    145156    /** 
    146      * getter for the localized message 
     157     * getter for the locale key 
    147158     * @return string 
    148159     */ 
    149     public function getLocaleMessage(){ 
    150         return $this->localizedMessage
     160    public function getLocaleKey(){ 
     161        return $this->localeKey
    151162    } 
    152163 
  • trunk/testapp/modules/unittest/classes/utcreateurls.class.php

    r386 r457  
    5050                $this->assertTrue( ($url == $trueResult[$k]), 'url attendue='.$trueResult[$k].'   url créée='.$url ); 
    5151            }catch(jExceptionSelector $e){ 
    52                 $this->assertTrue(false,'jExceptionSelector: '.$e->getMessage()); 
     52                $this->assertTrue(false,'jExceptionSelector: '.$e->getMessage().' ('.$e->getLocalKey().')'); 
    5353            }catch(jException $e){ 
    54                 $this->assertTrue(false,'jException: '.$e->getMessage()); 
     54                $this->assertTrue(false,'jException: '.$e->getMessage().' ('.$e->getLocalKey().')'); 
    5555            }catch(Exception $e){ 
    5656                $msgerr = '<br>Survenue : exception=Exception code='.$e->getCode().' msg='.$e->getMessage(); 
     
    7474                $this->assertTrue( false, ($res[0]?$msg2:$msg).'<br>Survenue : aucune !!!'); 
    7575            }catch(jExceptionSelector $e){ 
    76                 $msgerr = '<br>Survenue : exception=jExceptionSelector code='.$e->getCode().' localkey='.$e->getMessage(); 
     76                $msgerr = '<br>Survenue : exception=jExceptionSelector code='.$e->getCode().' localkey='.$e->getLocaleKey(); 
    7777                $this->assertTrue( ($res[0]==2) ,$msg2.$msgerr); 
    7878            }catch(jException $e){ 
    79                 $msgerr = '<br>Survenue : exception=jException code='.$e->getCode().' localkey='.$e->getMessage(); 
     79                $msgerr = '<br>Survenue : exception=jException code='.$e->getCode().' localkey='.$e->getLocaleKey(); 
    8080                $this->assertTrue( ($res[0]==1) ,$msg2.$msgerr); 
    8181            }catch(Exception $e){ 
  • trunk/testapp/modules/unittest/classes/utcreateurls.class.php

    r386 r457  
    5050                $this->assertTrue( ($url == $trueResult[$k]), 'url attendue='.$trueResult[$k].'   url créée='.$url ); 
    5151            }catch(jExceptionSelector $e){ 
    52                 $this->assertTrue(false,'jExceptionSelector: '.$e->getMessage()); 
     52                $this->assertTrue(false,'jExceptionSelector: '.$e->getMessage().' ('.$e->getLocalKey().')'); 
    5353            }catch(jException $e){ 
    54                 $this->assertTrue(false,'jException: '.$e->getMessage()); 
     54                $this->assertTrue(false,'jException: '.$e->getMessage().' ('.$e->getLocalKey().')'); 
    5555            }catch(Exception $e){ 
    5656                $msgerr = '<br>Survenue : exception=Exception code='.$e->getCode().' msg='.$e->getMessage(); 
     
    7474                $this->assertTrue( false, ($res[0]?$msg2:$msg).'<br>Survenue : aucune !!!'); 
    7575            }catch(jExceptionSelector $e){ 
    76                 $msgerr = '<br>Survenue : exception=jExceptionSelector code='.$e->getCode().' localkey='.$e->getMessage(); 
     76                $msgerr = '<br>Survenue : exception=jExceptionSelector code='.$e->getCode().' localkey='.$e->getLocaleKey(); 
    7777                $this->assertTrue( ($res[0]==2) ,$msg2.$msgerr); 
    7878            }catch(jException $e){ 
    79                 $msgerr = '<br>Survenue : exception=jException code='.$e->getCode().' localkey='.$e->getMessage(); 
     79                $msgerr = '<br>Survenue : exception=jException code='.$e->getCode().' localkey='.$e->getLocaleKey(); 
    8080                $this->assertTrue( ($res[0]==1) ,$msg2.$msgerr); 
    8181            }catch(Exception $e){ 
  • trunk/testapp/modules/unittest/classes/utdao_conditions.class.php

    r450 r457  
    101101 
    102102        }catch(jDaoXmlException $e){ 
    103             $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     103            $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    104104        }catch(Exception $e){ 
    105105            $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utdao_conditions.class.php

    r450 r457  
    101101 
    102102        }catch(jDaoXmlException $e){ 
    103             $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     103            $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    104104        }catch(Exception $e){ 
    105105            $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utdao_parser.class.php

    r449 r457  
    193193                $this->assertComplexIdenticalStr($p, $t[1]); 
    194194            }catch(jDaoXmlException $e){ 
    195                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     195                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    196196            }catch(Exception $e){ 
    197197                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    307307                $this->fail("Pas d'exception survenue !"); 
    308308            }catch(jDaoXmlException $e){ 
    309                 $this->assertEqual($e->getMessage(), $t[1]); 
    310                 $this->assertEqual($e->localeParams, $t[2]); 
     309                $this->assertEqual($e->getLocaleKey(), $t[1]); 
     310                $this->assertEqual($e->getLocaleParameters(), $t[2]); 
    311311            }catch(Exception $e){ 
    312312                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    406406                $this->assertComplexIdenticalStr($p, $t[1]); 
    407407            }catch(jDaoXmlException $e){ 
    408                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     408                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    409409            }catch(Exception $e){ 
    410410                $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utdao_parser.class.php

    r449 r457  
    193193                $this->assertComplexIdenticalStr($p, $t[1]); 
    194194            }catch(jDaoXmlException $e){ 
    195                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     195                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    196196            }catch(Exception $e){ 
    197197                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    307307                $this->fail("Pas d'exception survenue !"); 
    308308            }catch(jDaoXmlException $e){ 
    309                 $this->assertEqual($e->getMessage(), $t[1]); 
    310                 $this->assertEqual($e->localeParams, $t[2]); 
     309                $this->assertEqual($e->getLocaleKey(), $t[1]); 
     310                $this->assertEqual($e->getLocaleParameters(), $t[2]); 
    311311            }catch(Exception $e){ 
    312312                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    406406                $this->assertComplexIdenticalStr($p, $t[1]); 
    407407            }catch(jDaoXmlException $e){ 
    408                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage().' ('.$e->getMessage().')'); 
     408                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    409409            }catch(Exception $e){ 
    410410                $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utdao_parser2.class.php

    r450 r457  
    308308                $this->assertComplexIdenticalStr($p, $t[1]); 
    309309            }catch(jDaoXmlException $e){ 
    310                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage()); 
     310                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage()); 
    311311            }catch(Exception $e){ 
    312312                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    357357                $this->fail("Pas d'exception survenue !"); 
    358358            }catch(jDaoXmlException $e){ 
    359                 $this->assertEqual($e->getMessage(), $t[1]); 
    360                 $this->assertEqual($e->localeParams, $t[2]); 
     359                $this->assertEqual($e->getLocaleKey(), $t[1]); 
     360                $this->assertEqual($e->getLocaleParameters(), $t[2]); 
    361361            }catch(Exception $e){ 
    362362                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    393393            $this->fail("Pas d'exception survenue !"); 
    394394        }catch(jDaoXmlException $e){ 
    395             $this->assertEqual($e->getMessage(), 'jelix~daoxml.method.update.forbidden'); 
    396             $this->assertEqual($e->localeParams, array('','','tryupdate')); 
     395            $this->assertEqual($e->getLocaleKey(), 'jelix~daoxml.method.update.forbidden'); 
     396            $this->assertEqual($e->getLocaleParameters(), array('','','tryupdate')); 
    397397        }catch(Exception $e){ 
    398398            $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utdao_parser2.class.php

    r450 r457  
    308308                $this->assertComplexIdenticalStr($p, $t[1]); 
    309309            }catch(jDaoXmlException $e){ 
    310                 $this->fail("Exception sur le contenu xml inattendue : ".$e->getLocaleMessage()); 
     310                $this->fail("Exception sur le contenu xml inattendue : ".$e->getMessage()); 
    311311            }catch(Exception $e){ 
    312312                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    357357                $this->fail("Pas d'exception survenue !"); 
    358358            }catch(jDaoXmlException $e){ 
    359                 $this->assertEqual($e->getMessage(), $t[1]); 
    360                 $this->assertEqual($e->localeParams, $t[2]); 
     359                $this->assertEqual($e->getLocaleKey(), $t[1]); 
     360                $this->assertEqual($e->getLocaleParameters(), $t[2]); 
    361361            }catch(Exception $e){ 
    362362                $this->fail("Exception inconnue : ".$e->getMessage()); 
     
    393393            $this->fail("Pas d'exception survenue !"); 
    394394        }catch(jDaoXmlException $e){ 
    395             $this->assertEqual($e->getMessage(), 'jelix~daoxml.method.update.forbidden'); 
    396             $this->assertEqual($e->localeParams, array('','','tryupdate')); 
     395            $this->assertEqual($e->getLocaleKey(), 'jelix~daoxml.method.update.forbidden'); 
     396            $this->assertEqual($e->getLocaleParameters(), array('','','tryupdate')); 
    397397        }catch(Exception $e){ 
    398398            $this->fail("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utjdb_profile.class.php

    r444 r457  
    5555            $this->fail('getting a wrong profil doesn\'t generate an exception'); 
    5656        }catch(jException $e){ 
    57             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.unknow', 'wrong exception on getting a wrong profil ('.$e->getMessage().')'); 
     57            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.unknow', 'wrong exception on getting a wrong profil ('.$e->getLocaleKey().')'); 
    5858        } 
    5959 
     
    6262            $this->fail('getting a wrong profil option doesn\'t generate an exception'); 
    6363        }catch(jException $e){ 
    64             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.type.unknow', 'wrong exception on getting a wrong profil option ('.$e->getMessage().')'); 
     64            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.type.unknow', 'wrong exception on getting a wrong profil option ('.$e->getLocaleKey().')'); 
    6565        } 
    6666 
     
    6969            $this->fail('getting a profil option with a wrong name doesn\'t generate an exception'); 
    7070        }catch(jException $e){ 
    71             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.unknow', 'wrong exception on getting a profil option with a wrong name ('.$e->getMessage().')'); 
     71            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.unknow', 'wrong exception on getting a profil option with a wrong name ('.$e->getLocaleKey().')'); 
    7272        } 
    7373    } 
  • trunk/testapp/modules/unittest/classes/utjdb_profile.class.php

    r444 r457  
    5555            $this->fail('getting a wrong profil doesn\'t generate an exception'); 
    5656        }catch(jException $e){ 
    57             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.unknow', 'wrong exception on getting a wrong profil ('.$e->getMessage().')'); 
     57            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.unknow', 'wrong exception on getting a wrong profil ('.$e->getLocaleKey().')'); 
    5858        } 
    5959 
     
    6262            $this->fail('getting a wrong profil option doesn\'t generate an exception'); 
    6363        }catch(jException $e){ 
    64             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.type.unknow', 'wrong exception on getting a wrong profil option ('.$e->getMessage().')'); 
     64            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.type.unknow', 'wrong exception on getting a wrong profil option ('.$e->getLocaleKey().')'); 
    6565        } 
    6666 
     
    6969            $this->fail('getting a profil option with a wrong name doesn\'t generate an exception'); 
    7070        }catch(jException $e){ 
    71             $this->assertEqual($e->getMessage(),'jelix~db.error.profil.unknow', 'wrong exception on getting a profil option with a wrong name ('.$e->getMessage().')'); 
     71            $this->assertEqual($e->getLocaleKey(),'jelix~db.error.profil.unknow', 'wrong exception on getting a profil option with a wrong name ('.$e->getLocaleKey().')'); 
    7272        } 
    7373    } 
  • trunk/testapp/modules/unittest/classes/utjtplexpr.class.php

    r435 r457  
    131131                $this->assertEqualOrDiff($t, $res); 
    132132            }catch(jException $e){ 
    133                 $this->fail("Test '$k', Exception jelix inconnue : ".$e->getLocaleMessage()); 
     133                $this->fail("Test '$k', Exception jelix inconnue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    134134            }catch(Exception $e){ 
    135135                $this->fail("Test '$k', Exception inconnue : ".$e->getMessage()); 
     
    144144            try{ 
    145145                $res = $compil->testParseVarExpr($k); 
    146                 $this->fail("Exception non survenu pour le test '$k' : ".$e->getMessage()); 
     146                $this->fail("Exception non survenu pour le test '$k' "); 
    147147            }catch(jException $e){ 
    148                 //$this->sendMessage($e->getLocaleMessage()); 
    149                 $this->assertEqualOrDiff($t[0], $e->getMessage()); 
    150                 $this->assertEqual($t[1], $e->localeParams); 
     148                //$this->sendMessage($e->getMessage()); 
     149                $this->assertEqualOrDiff($t[0], $e->getLocaleKey()); 
     150                $this->assertEqual($t[1], $e->getLocaleParameters()); 
    151151            }catch(Exception $e){ 
    152152                $this->pass("Exception inconnue : ".$e->getMessage()); 
  • trunk/testapp/modules/unittest/classes/utjtplexpr.class.php

    r435 r457  
    131131                $this->assertEqualOrDiff($t, $res); 
    132132            }catch(jException $e){ 
    133                 $this->fail("Test '$k', Exception jelix inconnue : ".$e->getLocaleMessage()); 
     133                $this->fail("Test '$k', Exception jelix inconnue : ".$e->getMessage().' ('.$e->getLocalKey().')'); 
    134134            }catch(Exception $e){ 
    135135                $this->fail("Test '$k', Exception inconnue : ".$e->getMessage()); 
     
    144144            try{ 
    145145                $res = $compil->testParseVarExpr($k); 
    146                 $this->fail("Exception non survenu pour le test '$k' : ".$e->getMessage()); 
     146                $this->fail("Exception non survenu pour le test '$k' "); 
    147147            }catch(jException $e){ 
    148                 //$this->sendMessage($e->getLocaleMessage()); 
    149                 $this->assertEqualOrDiff($t[0], $e->getMessage()); 
    150                 $this->assertEqual($t[1], $e->localeParams); 
     148                //$this->sendMessage($e->getMessage()); 
     149                $this->assertEqualOrDiff($t[0], $e->getLocaleKey()); 
     150                $this->assertEqual($t[1], $e->getLocaleParameters()); 
    151151            }catch(Exception $e){ 
    152152                $this->pass("Exception inconnue : ".$e->getMessage()); 
Download in other formats: Unified Diff Zip Archive