コード例 #1
0
 /**
  * Parses an exception into a content type
  * @access public
  * @param Exception $e The exception to parse
  * @param string $contentType The type of content to return
  * @param string $recoverer The recoverer used to recover from the exception
  * @return string A parsed verion of the exception as the supplied content type
  */
 public static function parse(Exception $e, $contentType = self::HTML, $recoverer = null)
 {
     $out = '';
     switch ($contentType) {
         default:
         case self::PLAINTEXT:
             $out .= sfl('###### ATSUMI has caught an Exception : %s', date(DATE_ATOM));
             $out .= sfl("\n" . ' >> %s <<', $e->getMessage());
             $out .= sfl("\n" . 'Exception type: %s', get_class($e));
             if ($e instanceof ErrorException) {
                 $out .= sfl("\n" . 'Severity level: ' . $e->getSeverity());
             }
             $out .= sfl("\n" . '%s #%s', $e->getFile(), $e->getLine());
             /* Show the request URL if avalable */
             if (isset($_SERVER) && is_array($_SERVER) && array_key_exists('HTTP_HOST', $_SERVER) && array_key_exists('REQUEST_URI', $_SERVER)) {
                 $out .= sfl("\nRequest: http://%s", $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             }
             /* Show the referer URL if avalable */
             if (isset($_SERVER) && is_array($_SERVER) && array_key_exists('HTTP_REFERER', $_SERVER)) {
                 $out .= sfl("\nReferer: %s", $_SERVER['HTTP_REFERER']);
             }
             if (!is_null($recoverer)) {
                 $out .= sfl("\n" . 'Recoverer: %s()', is_object($recoverer) ? get_class($recoverer) : $recoverer);
                 $out .= sfl('Recoverer action: %s', $recoverer->getActionDetails());
             }
             if (isset($e->details) && !is_null($e->details)) {
                 $out .= sfl("\n" . '-Additional Detail');
                 $out .= sfl('%s', pretty($e->details));
             }
             if ($e instanceof atsumi_AbstractException) {
                 $out .= sfl("\n" . '-How to resolve this issue');
                 $out .= sfl($e->getInstructions('text/plain'));
             }
             $out .= sfl("\n" . '-Stack Trace');
             $out .= sfl('%s', atsumi_ErrorParser::formatTrace($e->getTrace()));
             $out .= sfl('###### End of Exception ' . "\n\n");
             break;
         case 'text/html':
             $out .= sfl(self::getHtmlCss());
             $out .= sfl('<div class="atsumiError">');
             $out .= sfl('<h3><strong>ATSUMI</strong> has caught an Exception : <strong>%s</strong></h3>', date(DATE_ATOM));
             $out .= sfl('<h1>%s</h1>', $e->getMessage());
             $out .= sfl('<h4>Exception type: <strong>%s</strong></h4>', get_class($e));
             if ($e instanceof ErrorException) {
                 $out .= sfl('<h4>Severity level: <strong>%s</strong></h4>', $e->getSeverity());
             }
             $out .= sfl('<h2>%s #<strong>%s</strong></h2>', preg_replace('|\\/([a-zA-Z0-9\\-\\_\\.]+\\.php)|', '/<strong>\\1</strong>', htmlentities($e->getFile())), $e->getLine());
             /* Show the request URL if avalable */
             if (isset($_SERVER) && is_array($_SERVER) && array_key_exists('HTTP_HOST', $_SERVER) && array_key_exists('REQUEST_URI', $_SERVER)) {
                 $out .= sfl("<h4>Request: <strong><a href='http://%s'>http://%s</a></strong></h4>", $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             }
             /* Show the referer URL if avalable */
             if (isset($_SERVER) && is_array($_SERVER) && array_key_exists('HTTP_REFERER', $_SERVER)) {
                 $out .= sfl("<h4>Referer: <strong><a href='%s'>%s</a></strong></h4>", $_SERVER['HTTP_REFERER'], $_SERVER['HTTP_REFERER']);
             }
             if (!is_null($recoverer)) {
                 $out .= sfl('<h4>Recoverer: <strong>%s()</strong></h4>', is_object($recoverer) ? get_class($recoverer) : $recoverer);
                 $out .= sfl('<h4>Recoverer action: <strong>%s</strong></h4>', $recoverer->getActionDetails());
             }
             if (isset($e->details) && !is_null($e->details)) {
                 $out .= sfl('<br /><h3>Additional Detail</h3>');
                 $out .= sfl('<div class="atsumiDetailsContainer"><pre>%s</pre></div>', pretty($e->details));
             }
             if ($e instanceof atsumi_AbstractException) {
                 $out .= sfl('<br /><h3><strong>ATSUMI</strong>: How to resolve this issue</h3>');
                 $out .= sfl('<div class="atsumiDetailsContainer">%s</div>', $e->getInstructions('text/html'));
             }
             $out .= sfl('<br /><h4>Stack Trace</h4>');
             $out .= sfl('<div class="atsumiDetailsContainer"><pre>%s</pre></div>', atsumi_ErrorParser::formatTrace($e->getTrace(), 'text/html'));
             $out .= sfl('</div>');
             break;
     }
     return $out;
 }
コード例 #2
0
 /**
  * Preforms the required actions to recover from an exception
  * @access public
  * @param Exception $e The exception to recover from
  */
 public function recover($e)
 {
     $this->setHeaders();
     pf('%s', atsumi_ErrorParser::parse($e, self::getContentType(), $this));
     exit;
 }
コード例 #3
0
 /**
  * Used by an atsumi_Observable object to notify the lissener of an event
  * @access public
  * @param atsumi_Observable $sender The Observable object that called the observer
  * @param atsumi_EventArgs $args Any args related to the event
  */
 public function notify(atsumi_Observable $sender, atsumi_EventArgs $args)
 {
     $this->writeToLog(atsumi_ErrorParser::parse($args->exception, atsumi_ErrorParser::PLAINTEXT, $args->recoverer));
 }
コード例 #4
0
 /**
  * Used by an atsumi_Observable object to notify the lissener of an event
  * @access public
  * @param atsumi_Observable $sender The Observable object that called the observer
  * @param atsumi_EventArgs $args Any args related to the event
  */
 public function notify(atsumi_Observable $sender, atsumi_EventArgs $args)
 {
     if ($this->onlyWhenRecovering && !$args->recoverer) {
         return;
     }
     $this->mergeDataToSession(atsumi_ErrorParser::parse($args->exception, atsumi_ErrorParser::PLAINTEXT, $args->recoverer));
 }