[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/console/plugin/errorlog/ -> DarkConsoleErrorLogPluginAPI.php (source)

   1  <?php
   2  
   3  final class DarkConsoleErrorLogPluginAPI {
   4  
   5    private static $errors = array();
   6  
   7    private static $discardMode = false;
   8  
   9    public static function registerErrorHandler() {
  10      // NOTE: This forces PhutilReadableSerializer to load, so that we are
  11      // able to handle errors which fire from inside autoloaders (PHP will not
  12      // reenter autoloaders).
  13      PhutilReadableSerializer::printableValue(null);
  14      PhutilErrorHandler::setErrorListener(
  15        array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
  16    }
  17  
  18    public static function enableDiscardMode() {
  19      self::$discardMode = true;
  20    }
  21  
  22    public static function disableDiscardMode() {
  23      self::$discardMode = false;
  24    }
  25  
  26    public static function getErrors() {
  27      return self::$errors;
  28    }
  29  
  30    public static function handleErrors($event, $value, $metadata) {
  31      if (self::$discardMode) {
  32        return;
  33      }
  34  
  35      switch ($event) {
  36        case PhutilErrorHandler::EXCEPTION:
  37          // $value is of type Exception
  38          self::$errors[] = array(
  39            'details'   => $value->getMessage(),
  40            'event'     => $event,
  41            'file'      => $value->getFile(),
  42            'line'      => $value->getLine(),
  43            'str'       => $value->getMessage(),
  44            'trace'     => $metadata['trace'],
  45          );
  46          break;
  47        case PhutilErrorHandler::ERROR:
  48          // $value is a simple string
  49          self::$errors[] = array(
  50            'details'   => $value,
  51            'event'     => $event,
  52            'file'      => $metadata['file'],
  53            'line'      => $metadata['line'],
  54            'str'       => $value,
  55            'trace'     => $metadata['trace'],
  56          );
  57          break;
  58        case PhutilErrorHandler::PHLOG:
  59          // $value can be anything
  60          self::$errors[] = array(
  61            'details' => PhutilReadableSerializer::printShallow($value, 3),
  62            'event'   => $event,
  63            'file'    => $metadata['file'],
  64            'line'    => $metadata['line'],
  65            'str'     => PhutilReadableSerializer::printShort($value),
  66            'trace'   => $metadata['trace'],
  67          );
  68          break;
  69        default:
  70          error_log('Unknown event : '.$event);
  71          break;
  72      }
  73    }
  74  
  75  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1