00001 <?php 00002 00008 class spunQ_LocalizedException extends spunQ_Exception { 00009 00014 protected $translationKey; 00015 00020 protected $translationParameters; 00021 00027 protected $localizedParameters = array(); 00028 00035 public function __construct($translationKey = NULL, $translationParameters = array()) { 00036 if ($translationKey !== NULL) { 00037 $this->translationKey = $translationKey; 00038 $this->translationParameters = $translationParameters; 00039 } 00040 parent::__construct($this->getExtendedMessage()); 00041 return NULL; 00042 } 00043 00048 public function getExtendedMessage() { 00049 # XXX: Any changes here need to be copied over to LocalizedError 00050 $translationKey = $this->translationKey; 00051 $translationParameters = $this->translationParameters; 00052 if ($translationKey === NULL) { 00053 warning('Encountered LocalizedException without translation key'); 00054 $translationKey = 'spunQ.LocalizedException.UnknownException'; 00055 $translationParameters = array(); 00056 } 00057 if (!spunQ::isInitialized()) { 00058 if (empty($translationParameters)) { 00059 return $translationKey; 00060 } 00061 return $translationKey . '[' . implode(', ', $translationParameters) . ']'; 00062 } 00063 foreach ($this->localizedParameters as $index) { 00064 $translationParameters[$index] = spunQ_Language::getSystemLanguage()->translate($translationParameters[$index]); 00065 } 00066 return spunQ_Language::getSystemLanguage()->translate($translationKey, $translationParameters); 00067 } 00068 00073 public function getTranslationKey() { 00074 return $this->translationKey; 00075 } 00076 00081 public function getTranslationParameters() { 00082 return $this->translationParameters; 00083 } 00084 00085 } 00086
1.5.9