Beispiel #1
0
 /**
  * 
  * @param string|array $message
  * @param integer $code
  * @param Exception $previous
  */
 public function __construct($message, $code = 0, Exception $previous = null)
 {
     if (is_array($message)) {
         if (count($message) != 2) {
             throw new \Exception('Array argument should contain exactly two values');
         }
         // key O is key to message, key 1 contains a string or an array of strings
         $key = $message[0];
     } else {
         $key = $message;
     }
     $lang = Core::$lang;
     $res = Config\Loader::loadConfig('messages/exceptions/' . $this->_store . '.xml');
     //\Zend_Debug::dump($res); die;
     $this->_messages = $res['exceptions'];
     if (isset($this->_messages[$key])) {
         $messages = isset($this->_messages[$key]['labels']) ? $this->_messages[$key]['labels'] : array();
         if ($lang != 'en' && isset($messages[$lang])) {
             $str = $messages[$lang];
         } else {
             /* english version should always be available either under the 'en' key or in the parent-level 'label' key */
             $str = isset($messages['en']) ? $messages['en'] : $this->_messages[$key]['label'];
         }
         if ($str !== false && is_array($message)) {
             foreach ((array) $message[1] as $key => $val) {
                 $str = str_replace('%' . $key, is_object($val) ? get_class($val) : $val, $str);
             }
         }
     } else {
         $str = $key;
     }
     $str .= sprintf("\n(file: %s, line: %d", $this->getFile(), $this->getLine());
     if (Core::$env != Core::ENV_PROD) {
         $str .= "\n" . $this->getTraceAsString();
     }
     // if a previously caught exception is passed as parameter, its message is postfixed to current message
     if ($previous instanceof Exception) {
         $str .= "\n" . $previous->getMessage();
     }
     parent::__construct($str, (int) $code);
     //, $previous);
 }
Beispiel #2
0
 /**
  * Gestionnaire d'exceptions t41
  *
  * @param Exception $e
  */
 public static function exceptionHandler(Exception $e)
 {
     switch (View::getDisplayContext()) {
         case 'ajax':
             //  $ajax = new t41_Ajax();
             //  $ajax->setSendMessage($e->getMessage(), t41_Ajax::ERR);
             break;
         default:
             View::resetObjects('default');
             // to avoid infinite loop and fatal error, reset view content
             $error = new SimpleComponent();
             $error->setTitle('ERREUR FATALE : ' . html_entity_decode($e->getMessage()));
             if (self::$env == self::ENV_DEV) {
                 // in dev mode, also print out execution trace
                 $error->setContent('<br/><pre>' . $e->getTraceAsString() . '</pre>');
             }
             $error->register();
             exit(View::display());
             break;
     }
 }