Exemplo n.º 1
0
 /**
  * Attempts to unregister the error handler, restores the previous
  */
 function unregister()
 {
     restore_error_handler();
     restore_exception_handler();
     $this->_registered = false;
     return $this;
 }
Exemplo n.º 2
0
 /**
  * 负责分发错误到日志记录
  */
 public static function errorHandler($errno, $errstr, $errfile, $errline, $obj)
 {
     restore_error_handler();
     restore_exception_handler();
     // 处理@符号的情况
     if (!(error_reporting() !== 0 && $errno)) {
         return;
     }
     switch ($errno) {
         case E_NOTICE:
         case E_USER_NOTICE:
             $errors = "Notice";
             break;
         case E_WARNING:
         case E_USER_WARNING:
             $errors = "Warning";
             break;
         case E_ERROR:
         case E_USER_ERROR:
             $errors = "Fatal Error";
             break;
         default:
             $errors = "Unknown";
             break;
     }
     Flow::Log()->clear();
     Flow::Log()->error(sprintf("%s in %s on line %d", $errstr, $errfile, $errline));
     self::dieErrorLogs();
     return false;
 }
Exemplo n.º 3
0
 /**
  * constructor initializes the default database connection
  */
 public function __construct()
 {
     set_exception_handler(array(__CLASS__, 'fallback_handler'));
     restore_exception_handler();
     Config::set('db_dsn', 'mysql:host=' . Config::get('db_host') . ';dbname=' . Config::get('db_name'));
     $this->initDB();
 }
Exemplo n.º 4
0
 /**
  * Constructor
  *
  * @param HTTP\Request $request
  * @param HTTP\Response $response
  * @param string $format one of png, jpeg, gif
  */
 public function __construct(HTTP\Request $request, HTTP\Response $response, $format = 'png')
 {
     parent::__construct($request, $response);
     // to enabled jpgraphs graphical exception handler
     restore_exception_handler();
     if ($this->request->getParameter('width')) {
         $this->width = $this->request->getParameter('width');
     }
     if ($this->request->getParameter('height')) {
         $this->height = $this->request->getParameter('height');
     }
     $this->colors = Util\Configuration::read('colors');
     $this->graph = new \Graph($this->width, $this->height);
     $this->graph->img->SetImgFormat($format);
     // Specify what scale we want to use,
     $this->graph->SetScale('datlin');
     $this->graph->legend->SetPos(0.03, 0.06);
     $this->graph->legend->SetShadow(FALSE);
     $this->graph->legend->SetFrameWeight(1);
     $this->graph->SetMarginColor('white');
     $this->graph->SetYDeltaDist(65);
     $this->graph->yaxis->SetTitlemargin(36);
     $this->graph->SetTickDensity(TICKD_DENSE, TICKD_SPARSE);
     $this->graph->xaxis->SetFont(FF_ARIAL);
     $this->graph->xaxis->SetLabelAngle(45);
     $this->graph->xaxis->SetLabelFormatCallback(function ($label) {
         return date('j.n.y G:i', $label);
     });
     $this->graph->img->SetAntiAliasing(function_exists('imageantialias'));
 }
Exemplo n.º 5
0
 public function __construct()
 {
     set_exception_handler(array(__CLASS__, 'fallback_handler'));
     //database init
     $this->dbh = new PDO(Config::get('dsn'), Config::get('db_user'), Config::get('db_pass'));
     restore_exception_handler();
 }
Exemplo n.º 6
0
 /**
  * Returns the callable currently registered to handle uncaught exceptions
  * 
  * @return callable
  */
 protected function getCurrentExceptionHandler()
 {
     $handler = set_exception_handler(function () {
     });
     restore_exception_handler();
     return $handler;
 }
 public function handleException($exception)
 {
     // disable error capturing to avoid recursive errors
     restore_error_handler();
     restore_exception_handler();
     //        $event=new Exception($this,$exception);
     if ($exception instanceof NotFoundHttpException && !isset($_GET['r'])) {
         echo Yii::$app->runAction("wordpress-loader");
         //            try
         //            {
         //
         ////                $results =  Yii::$app->runAction("wordpress-loader");
         ////                Yii::$app->end();
         //            }
         //            catch(\Exception $exception) {
         //
         //                var_dump($exception);
         //                die;
         //
         //            }
         // if we throw an exception in Wordpress on a 404, we can use
         // our main error handler to handle the error
     }
     //        if(!$event->handled)
     //        {
     //            Yii::$app->handleException($exception);
     //        }
 }
 public function testConfigure()
 {
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $userHandler = function () {
     };
     $listener = new DebugHandlersListener($userHandler, $logger);
     $xHandler = new ExceptionHandler();
     $eHandler = new ErrorHandler();
     $eHandler->setExceptionHandler(array($xHandler, 'handle'));
     $exception = null;
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $listener->configure();
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
     $loggers = $eHandler->setLoggers(array());
     $this->assertArrayHasKey(E_DEPRECATED, $loggers);
     $this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
 }
Exemplo n.º 9
0
 /**
  * @param $modelname
  *
  * @internal param string $encoding
  *
  * @return string
  */
 public function run($modelname)
 {
     // Set up an independent AJAX error handler
     set_error_handler(array($this, 'error_handler'));
     set_exception_handler(array($this, 'exception_handler'));
     while (@ob_end_clean()) {
     }
     // clean any pending output buffers
     ob_start();
     // start a fresh one
     try {
         $container = RokUpdater_ServiceProvider::getInstance();
         $model_container_name = self::DEFAULT_MODEL_CONTEXT_PREFIX . strtolower($modelname);
         /** @var RokUpdater_Ajax_IModel $model */
         $model = $container->{$model_container_name};
         // set the result to the run
         $result = $model->run();
     } catch (Exception $ae) {
         $result = new stdClass();
         $result->status = "error";
         $result->message = $ae->getMessage();
         $result = json_encode($result);
     }
     // restore normal error handling;
     restore_error_handler();
     restore_exception_handler();
     return $result;
 }
Exemplo n.º 10
0
 /**
  * Start the shell and interactive console.
  *
  * @return int|void
  */
 public function main()
 {
     if (!class_exists('Psy\\Shell')) {
         $this->err('<error>Unable to load Psy\\Shell.</error>');
         $this->err('');
         $this->err('Make sure you have installed psysh as a dependency,');
         $this->err('and that Psy\\Shell is registered in your autoloader.');
         $this->err('');
         $this->err('If you are using composer run');
         $this->err('');
         $this->err('<info>$ php composer.phar require --dev psy/psysh</info>');
         $this->err('');
         return 1;
     }
     $this->out("You can exit with <info>`CTRL-C`</info> or <info>`exit`</info>");
     $this->out('');
     Log::drop('debug');
     Log::drop('error');
     $this->_io->setLoggers(false);
     restore_error_handler();
     restore_exception_handler();
     $psy = new PsyShell();
     $psy->run();
     return 0;
 }
Exemplo n.º 11
0
 public static function disableExceptionTrapping()
 {
     self::$exceptionTrappingOn = false;
     ini_set("display_errors", true);
     restore_error_handler();
     restore_exception_handler();
 }
Exemplo n.º 12
0
 static function _call($c)
 {
     try {
         if (__CLASS__ . '::' !== self::$class) {
             array_unshift($c, self::$class . __FUNCTION__);
         }
         call_user_func_array(array_shift($c), $c);
     } catch (\Exception $e) {
         $c = set_exception_handler('var_dump');
         restore_exception_handler();
         if (null !== $c) {
             call_user_func($c, $e);
         } else {
             /**/
             if (PHP_VERSION_ID >= 50306) {
                 throw $e;
                 /**/
             } else {
                 user_error("Uncaught exception '" . get_class($e) . "'" . ('' !== $e->getMessage() ? " with message '{$e->getMessage()}'" : "") . " in {$e->getFile()}:{$e->getLine()}" . PHP_EOL . "Stack trace:" . PHP_EOL . "{$e->getTraceAsString()}" . PHP_EOL, E_USER_WARNING);
                 /**/
             }
         }
         exit(255);
     }
 }
Exemplo n.º 13
0
 public function __construct()
 {
     $details = Config::get('Database');
     set_exception_handler(array(__CLASS__, 'error_handler'));
     parent::__construct("mysql:host={$details['host']};dbname={$details['name']}", $details['user'], $details['password']);
     restore_exception_handler();
 }
Exemplo n.º 14
0
 public function tearDown()
 {
     ini_set('display_errors', $this->displayErrors);
     error_reporting($this->errorReporting);
     restore_error_handler();
     restore_exception_handler();
 }
Exemplo n.º 15
0
Arquivo: tests.php Projeto: azuya/Wi3
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     // During a webui request we need to manually load PHPUnit
     if (!class_exists('PHPUnit_Util_Filter', FALSE) and !function_exists('phpunit_autoload')) {
         try {
             include_once 'PHPUnit/Autoload.php';
         } catch (ErrorException $e) {
             include_once 'PHPUnit/Framework.php';
         }
     }
     // Allow PHPUnit to handle exceptions and errors
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
     // As of PHPUnit v3.5 there are slight differences in the way files are black|whitelisted
     self::$phpunit_v35 = function_exists('phpunit_autoload');
     $config = Kohana::config('unittest');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         Kohana_Tests::blacklist($config->blacklist);
     }
 }
Exemplo n.º 16
0
 /**
  * Start the shell and interactive console.
  *
  * @return void
  */
 public function main()
 {
     if (!class_exists('Boris\\Boris')) {
         $this->err('<error>Unable to load Boris\\Boris.</error>');
         $this->err('');
         $this->err('Make sure you have installed boris as a dependency,');
         $this->err('and that Boris\\Boris is registered in your autoloader.');
         $this->err('');
         $this->err('If you are using composer run');
         $this->err('');
         $this->err('<info>$ php composer.phar require d11wtq/boris</info>');
         $this->err('');
         return 1;
     }
     if (!function_exists('pcntl_signal')) {
         $this->err('<error>No process control functions.</error>');
         $this->err('');
         $this->err('You are missing the pcntl extension, the interactive console requires this extension.');
         return 2;
     }
     $this->out('You can exit with <info>CTRL-D</info>');
     Log::drop('debug');
     Log::drop('error');
     $this->_io->setLoggers(false);
     restore_error_handler();
     restore_exception_handler();
     $boris = new Boris('app > ');
     $boris->start();
 }
Exemplo n.º 17
0
 /**
  * Configures the environment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_environment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     restore_exception_handler();
     restore_error_handler();
     spl_autoload_register(array('Unittest_tests', 'autoload'));
     Unittest_tests::$cache = ($cache = Kohana::cache('unittest_whitelist_cache')) === NULL ? array() : $cache;
 }
Exemplo n.º 18
0
 public function testConsoleEvent()
 {
     $dispatcher = new EventDispatcher();
     $listener = new DebugHandlersListener(null);
     $app = $this->getMock('Symfony\\Component\\Console\\Application');
     $app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
     $command = new Command(__FUNCTION__);
     $command->setApplication($app);
     $event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
     $dispatcher->addSubscriber($listener);
     $xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure')));
     $this->assertSame($xListeners, $dispatcher->getListeners());
     $exception = null;
     $eHandler = new ErrorHandler();
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $xHandler = $eHandler->setExceptionHandler('var_dump');
     $this->assertInstanceOf('Closure', $xHandler);
     $app->expects($this->once())->method('renderException');
     $xHandler(new \Exception());
 }
Exemplo n.º 19
0
 /**
  * Configures the enviroment for testing
  *
  * Does the following:
  *
  * * Loads the phpunit framework (for the web ui)
  * * Restores exception phpunit error handlers (for cli)
  * * registeres an autoloader to load test files
  */
 public static function configure_enviroment($do_whitelist = TRUE, $do_blacklist = TRUE)
 {
     if (!class_exists('PHPUnit_Util_Filter', FALSE)) {
         // Make sure the PHPUnit classes are available
         require_once 'PHPUnit/Framework.php';
     }
     if (Kohana::$is_cli) {
         restore_exception_handler();
         restore_error_handler();
     }
     spl_autoload_register(array('Kohana_Tests', 'autoload'));
     Kohana_Tests::$cache = ($cache = Kohana::cache('phpunit_whitelist_cache')) === NULL ? array() : $cache;
     $config = Kohana::config('phpunit');
     if ($do_whitelist and $config->use_whitelist) {
         self::whitelist();
     }
     if ($do_blacklist and count($config['blacklist'])) {
         foreach ($config->blacklist as $item) {
             if (is_dir($item)) {
                 PHPUnit_Util_Filter::addDirectoryToFilter($item);
             } else {
                 PHPUnit_Util_Filter::addFileToFilter($item);
             }
         }
     }
 }
Exemplo n.º 20
0
 /**
  * Disable Kohana exception handling.
  *
  * @return  void
  */
 public static function disable()
 {
     if (Kohana_Exception::$enabled) {
         restore_exception_handler();
         Kohana_Exception::$enabled = FALSE;
     }
 }
Exemplo n.º 21
0
 protected function _before()
 {
     $this->cleanTestDb();
     // Necessary to actually have a chance to spot errors (Yii Autoloader issue?)
     restore_error_handler();
     restore_exception_handler();
 }
Exemplo n.º 22
0
 public function __destruct()
 {
     $this->output->close();
     $this->output->flush();
     restore_error_handler();
     restore_exception_handler();
 }
Exemplo n.º 23
0
 public function __destruct()
 {
     if ($this->options->logUncaughtExceptions) {
         restore_error_handler();
         restore_exception_handler();
     }
 }
Exemplo n.º 24
0
 /**
  * @param $model
  * @param $action
  * @param $params
  *
  * @return string
  */
 public static function run($model, $action, $params)
 {
     // Set up an independent AJAX error handler
     set_error_handler(array('RokCommon_Ajax', 'error_handler'));
     set_exception_handler(array('RokCommon_Ajax', 'exception_handler'));
     while (@ob_end_clean()) {
     }
     // clean any pending output buffers
     ob_start();
     // start a fresh one
     $result = null;
     try {
         /** @var RokCommon_Ajax_ModelLoader $ajaxModelLoader  */
         $ajaxModelLoader = RokCommon_ClassLoader::getLoader('AjaxModels');
         // get a model class instance
         $modelInstance = $ajaxModelLoader->getModel($model);
         $decoded_params = json_decode($params);
         if (null == $decoded_params && strlen($params) > 0) {
             throw new RokCommon_Ajax_Exception('Invalid JSON for params');
         }
         // set the result to the run
         $result = $modelInstance->run($action, $decoded_params);
     } catch (Exception $ae) {
         $result = new RokCommon_Ajax_Result();
         $result->setAsError();
         $result->setMessage($ae->getMessage());
     }
     $encoded_result = json_encode($result);
     // restore normal error handling;
     restore_error_handler();
     restore_exception_handler();
     return $encoded_result;
 }
Exemplo n.º 25
0
 public function __construct()
 {
     set_exception_handler(array(__CLASS__, 'exception_handler'));
     $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => $this->persistent);
     parent::__construct('mysql:host=' . $this->host . ';dbname=' . $this->database . ';charset=' . $this->charset, $this->user, $this->password, $options);
     restore_exception_handler();
 }
Exemplo n.º 26
0
 /**
  * registerErrorHandler
  *
  * @return  void
  */
 public static function registerErrorHandler()
 {
     restore_error_handler();
     restore_exception_handler();
     set_error_handler(array(__CLASS__, 'error'));
     set_exception_handler(array(__CLASS__, 'exception'));
 }
 public function testExceptionHandlerIsIset()
 {
     $cb = function () {
     };
     $this->assertEquals(array($this->errorHandler, 'exceptionHandler'), set_exception_handler($cb));
     restore_exception_handler();
 }
Exemplo n.º 28
0
 protected function in()
 {
     $path_to_phpgroupware = dirname(__FILE__) . '/../..';
     // need to be adapted if this script is moved somewhere else
     $_GET['domain'] = 'default';
     $GLOBALS['phpgw_info']['flags'] = array('currentapp' => 'login', 'noapi' => True);
     /**
      * Include phpgroupware header
      */
     include $path_to_phpgroupware . '/header.inc.php';
     unset($GLOBALS['phpgw_info']['flags']['noapi']);
     $db_type = $GLOBALS['phpgw_domain'][$_GET['domain']]['db_type'];
     if ($db_type == 'postgres') {
         $db_type = 'pgsql';
     }
     if (!extension_loaded($db_type) && !dl($db_type . '.so')) {
         echo "Extension '{$db_type}' is not loaded and can't be loaded via dl('{$db_type}.so') !!!\n";
     }
     $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db';
     /**
      * Include API functions
      */
     include PHPGW_API_INC . '/functions.inc.php';
     for ($i = 0; $i < 10; $i++) {
         restore_error_handler();
         //Remove at least 10 levels of custom error handling
     }
     for ($i = 0; $i < 10; $i++) {
         restore_exception_handler();
         //Remove at least 10 levels of custom exception handling
     }
     $this->initializeContext();
 }
 /**
  * Revert the handlers back to their original state.
  */
 public static function reset()
 {
     if (isset(self::$instance)) {
         restore_error_handler();
         restore_exception_handler();
     }
     self::$instance = null;
 }
Exemplo n.º 30
0
 public static function setUpBeforeClass()
 {
     // Necessary to actually have a chance to spot errors (Yii Autoloader issue?)
     restore_error_handler();
     restore_exception_handler();
     // Clean test db
     Yii::app()->db->createCommand("DELETE FROM book")->execute();
 }