Пример #1
1
Файл: Core.php Проект: z7/hydra
 function __construct(array $config = array())
 {
     $this->_config =& $config;
     // Try to locate app folder.
     if (!isset($config['app_dir'])) {
         $cwd = getcwd();
         while (!is_dir("{$cwd}/app")) {
             if ($cwd == dirname($cwd)) {
                 throw new \LogicException('/app folder not found.');
             }
             $cwd = dirname($cwd);
         }
         $config['app_dir'] = "{$cwd}/app";
     }
     $is_web_request = isset($_SERVER['SERVER_NAME']);
     $config += array('debug' => !$is_web_request || $_SERVER['SERVER_NAME'] == 'localhost', 'register_exception_handler' => $is_web_request, 'register_error_handler' => $is_web_request, 'core_dir' => __DIR__ . '/../..', 'data_dir' => "{$config['app_dir']}/../data");
     $this->exception_handler = new ExceptionHandler($this->debug);
     if ($this->register_exception_handler) {
         set_exception_handler(array($this->exception_handler, 'handle'));
     }
     if ($this->register_error_handler) {
         $this->errorHandler = \Symfony\Component\HttpKernel\Debug\ErrorHandler::register();
     }
     foreach (array($config['data_dir'], "{$config['data_dir']}/cache", "{$config['data_dir']}/logs") as $dir) {
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     }
 }
Пример #2
0
 public function run()
 {
     $this->start = microtime(true);
     ob_start();
     error_reporting(E_STRICT & E_ALL);
     error_reporting(E_STRICT | E_ALL);
     set_error_handler(array(&$this, "errorHandler"));
     KalturaLog::debug("Params [" . print_r($this->params, true) . "]");
     try {
         $this->setSerializerByFormat();
     } catch (Exception $e) {
         return new kRendererDieError($e->getCode(), $e->getMessage());
     }
     if ($this->service == "multirequest") {
         set_exception_handler(null);
         $result = $this->handleMultiRequest();
     } else {
         $success = true;
         $errorCode = null;
         $this->onRequestStart($this->service, $this->action, $this->params);
         try {
             $result = $this->dispatcher->dispatch($this->service, $this->action, $this->params);
         } catch (Exception $ex) {
             $success = false;
             $errorCode = $ex->getCode();
             $result = $this->getExceptionObject($ex, $this->service, $this->action);
         }
         $this->onRequestEnd($success, $errorCode);
     }
     ob_end_clean();
     $this->end = microtime(true);
     return $this->serializeResponse($result);
 }
Пример #3
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());
 }
 /**
  * @expectedException \Symfony\Component\Debug\Exception\DummyException
  */
 public function testStacking()
 {
     // the ContextErrorException must not be loaded to test the workaround
     // for https://bugs.php.net/65322.
     if (class_exists('Symfony\\Component\\Debug\\Exception\\ContextErrorException', false)) {
         $this->markTestSkipped('The ContextErrorException class is already loaded.');
     }
     $exceptionHandler = $this->getMock('Symfony\\Component\\Debug\\ExceptionHandler', array('handle'));
     set_exception_handler(array($exceptionHandler, 'handle'));
     $that = $this;
     $exceptionCheck = function ($exception) use($that) {
         $that->assertInstanceOf('Symfony\\Component\\Debug\\Exception\\ContextErrorException', $exception);
         $that->assertEquals(E_STRICT, $exception->getSeverity());
         $that->assertStringStartsWith(__FILE__, $exception->getFile());
         $that->assertRegexp('/^Runtime Notice: Declaration/', $exception->getMessage());
     };
     $exceptionHandler->expects($this->once())->method('handle')->will($this->returnCallback($exceptionCheck));
     ErrorHandler::register();
     try {
         // Trigger autoloading + E_STRICT at compile time
         // which in turn triggers $errorHandler->handle()
         // that again triggers autoloading for ContextErrorException.
         // Error stacking works around the bug above and everything is fine.
         eval('
             namespace ' . __NAMESPACE__ . ';
             class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
         ');
     } catch (\Exception $e) {
         restore_error_handler();
         restore_exception_handler();
         throw $e;
     }
     restore_error_handler();
     restore_exception_handler();
 }
Пример #5
0
 /**
 +----------------------------------------------------------
 * 应用程序初始化
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 */
 public static function run()
 {
     // 设定错误和异常处理
     set_error_handler(array('App', "appError"));
     set_exception_handler(array('App', "appException"));
     //[RUNTIME]
     // 检查项目是否编译过
     // 在部署模式下会自动在第一次执行的时候编译项目
     if (defined('RUNTIME_MODEL')) {
         // 运行模式无需载入项目编译缓存
     } elseif (is_file(RUNTIME_PATH . '~app.php') && (!is_file(CONFIG_PATH . 'config.php') || filemtime(RUNTIME_PATH . '~app.php') > filemtime(CONFIG_PATH . 'config.php'))) {
         // 直接读取编译后的项目文件
         C(include RUNTIME_PATH . '~app.php');
     } else {
         // 预编译项目
         App::build();
     }
     //[/RUNTIME]
     // 取得模块和操作名称
     define('MODULE_NAME', App::getModule());
     // Module名称
     define('ACTION_NAME', App::getAction());
     // Action操作
     // 记录应用初始化时间
     if (C('SHOW_RUN_TIME')) {
         $GLOBALS['_initTime'] = microtime(TRUE);
     }
     // 执行操作
     R(MODULE_NAME, ACTION_NAME);
     // 保存日志记录
     if (C('LOG_RECORD')) {
         Log::save();
     }
     return;
 }
Пример #6
0
 /**
  * Module bootstrap.
  */
 public function onBootstrap($e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $options = $sm->get('loslog_options');
     if ($options->getUseErrorLogger()) {
         $logger = $sm->get('LosLog\\Log\\ErrorLogger');
         $eventManager = $e->getApplication()->getEventManager();
         $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR, [$logger, 'dispatchError'], -100);
     }
     if ($options->getUseSqlLogger()) {
         $em = $sm->get('doctrine.entitymanager.orm_default');
         $sqlLogger = $sm->get('LosLog\\Log\\SqlLogger');
         $sqlLogger->addLoggerTo($em);
     }
     if ($options->getUseRollbarLogger()) {
         $rollbar = $sm->get('RollbarNotifier');
         if ($options->getExceptionhandler()) {
             set_exception_handler(array($rollbar, 'report_exception'));
             $eventManager = $e->getApplication()->getEventManager();
             $eventManager->attach('dispatch.error', function (Event $event) use($rollbar) {
                 $exception = $event->getResult()->exception;
                 if ($exception) {
                     $rollbar->report_exception($exception);
                 }
             });
         }
         if ($options->getErrorhandler()) {
             set_error_handler(array($rollbar, 'report_php_error'));
         }
         if ($options->getShutdownfunction()) {
             register_shutdown_function($this->shutdownHandler($rollbar));
         }
     }
 }
Пример #7
0
 /**
  * @param Config $config
  * @param Request $request
  * @param Response $response
  */
 public function __construct(Config $config, Request $request, Response $response)
 {
     $this->config = $config;
     $this->request = $request;
     $this->response = $response;
     set_exception_handler([$this, 'handleException']);
 }
Пример #8
0
 function __construct($name = '', $desc = '')
 {
     $this->_name = $name;
     $this->_desc = $desc;
     array_push($this->_options, new Option('-h, --help', 'Output usage information'));
     set_exception_handler([$this, 'exception']);
 }
Пример #9
0
 /**
  * This method is used to enable debugging within your Ulfberht application.
  */
 public static function enable()
 {
     error_reporting(E_ALL);
     ini_set('display_errors', '1');
     set_exception_handler(['ulfberht\\debug', 'ulfberhtExceptionHandler']);
     self::$isEnabled = true;
 }
Пример #10
0
 public function __construct($plan = null, array $options = array())
 {
     $this->options = array('base_dir' => null, 'output' => 'tap', 'force_colors' => false, 'verbose' => false, 'serialize' => false, 'coverage' => false);
     foreach (LimeShell::parseArguments($GLOBALS['argv']) as $argument => $value) {
         $this->options[str_replace('-', '_', $argument)] = $value;
     }
     $this->options = array_merge($this->options, $options);
     $this->options['base_dir'] = realpath($this->options['base_dir']);
     list($file, $line) = LimeTrace::findCaller('LimeTest');
     if ($this->options['coverage']) {
         $this->output = new LimeOutputCoverage();
     } elseif (is_string($this->options['output'])) {
         $factory = new LimeOutputFactory($this->options);
         $this->output = $factory->create($this->options['output']);
     } else {
         $this->output = $this->options['output'];
     }
     $this->output->focus($file);
     if (!is_null($plan)) {
         $this->output->plan($plan);
     }
     set_error_handler(array($this, 'handleError'));
     // make sure that exceptions that are not caught by the test runner are
     // caught and formatted in an appropriate way
     set_exception_handler(array($this, 'handleException'));
 }
Пример #11
0
 /**
  * 环境初始化
  * @param array $config
  * @return void
  */
 public static function init(array $config = null)
 {
     if (is_array($config)) {
         self::$config = array_merge(self::$config, $config);
     }
     /**
      * 设置自动载入函数
      */
     if (self::$config['autoload']) {
         if (function_exists('__autoload')) {
             spl_autoload_register('__autoload');
         }
         spl_autoload_register(array('Base_Common', 'autoload'));
     }
     /**
      * GPC
      */
     if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
         $_GET = self::stripslashesRecursive($_GET);
         $_POST = self::stripslashesRecursive($_POST);
         $_COOKIE = self::stripslashesRecursive($_COOKIE);
         reset($_GET);
         reset($_POST);
         reset($_COOKIE);
     }
     /**
      * 设置异常抛出
      */
     set_exception_handler(array('Base_Common', 'exceptionHandle'));
     /**
      * 设置时区
      */
     date_default_timezone_set(self::$config['timezone']);
 }
Пример #12
0
 public function testNotice()
 {
     $exceptionHandler = $this->getMock('Symfony\\Component\\Debug\\ExceptionHandler', array('handle'));
     set_exception_handler(array($exceptionHandler, 'handle'));
     $that = $this;
     $exceptionCheck = function ($exception) use($that) {
         $that->assertInstanceOf('Symfony\\Component\\Debug\\Exception\\ContextErrorException', $exception);
         $that->assertEquals(E_NOTICE, $exception->getSeverity());
         $that->assertEquals(__LINE__ + 40, $exception->getLine());
         $that->assertEquals(__FILE__, $exception->getFile());
         $that->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
         $that->assertArrayHasKey('foobar', $exception->getContext());
         $trace = $exception->getTrace();
         $that->assertEquals(__FILE__, $trace[0]['file']);
         $that->assertEquals('Symfony\\Component\\Debug\\ErrorHandler', $trace[0]['class']);
         $that->assertEquals('handle', $trace[0]['function']);
         $that->assertEquals('->', $trace[0]['type']);
         $that->assertEquals(__FILE__, $trace[1]['file']);
         $that->assertEquals(__CLASS__, $trace[1]['class']);
         $that->assertEquals('triggerNotice', $trace[1]['function']);
         $that->assertEquals('::', $trace[1]['type']);
         $that->assertEquals(__CLASS__, $trace[2]['class']);
         $that->assertEquals('testNotice', $trace[2]['function']);
         $that->assertEquals('->', $trace[2]['type']);
     };
     $exceptionHandler->expects($this->once())->method('handle')->will($this->returnCallback($exceptionCheck));
     ErrorHandler::register();
     try {
         self::triggerNotice($this);
     } catch (DummyException $e) {
         // if an exception is thrown, the test passed
     }
     restore_error_handler();
 }
Пример #13
0
 public static function init()
 {
     ### { PHP Config } ###
     ini_set('magic_quotes_gpc', 0);
     ini_set('magic_quotes_runtime', 0);
     ini_set('magic_quotes_sybase', 0);
     ini_set('session.use_only_cookies', 1);
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     ### { Class Autoloading } ###
     spl_autoload_register('Clap::classLoader');
     self::$loadedClass['Clap'] = Clap::LIBRARIES_LOCATION . 'Clap/Clap.php';
     ### { Error & Exception } ###
     error_reporting(E_ALL);
     ini_set('display_errors', true);
     set_error_handler('Clap_Error::errorHandler');
     set_exception_handler('Clap_Error::exceptionHandler');
     ### { Browser Output } ###
     if (!ob_get_level()) {
         ob_start();
     }
     // ignore_user_abort(true);
     ### { Start Services } ###
     $Conf = Clap::getService('Config');
     $Sess = Clap::getService('Session');
     $Cach = Clap::getService('Cache');
     $Site = Clap::getService('Site');
     ### { Site Operations } ###
     $Site->redirForm();
     $Site->exeFlash();
     $Site->insert();
     ### { Send HTML & Save } ###
     $Site->close();
 }
Пример #14
0
 /**
  * Constructor.
  *
  * @param   object  &$subject  The object to observe
  * @param   array   $config    An optional associative array of configuration settings.
  *
  * @since   1.6
  */
 public function __construct(&$subject, $config)
 {
     parent::__construct($subject, $config);
     // Set the error handler for E_ERROR to be the class handleError method.
     JError::setErrorHandling(E_ERROR, 'callback', array('PlgSystemRedirect', 'handleError'));
     set_exception_handler(array('PlgSystemRedirect', 'handleError'));
 }
 static function init()
 {
     set_exception_handler("MVCCore::exception");
     set_error_handler("MVCCore::error");
     register_shutdown_function("MVCCore::shutdown");
     spl_autoload_register("MVCCore::autoload");
 }
Пример #16
0
 public function __construct(TemplateEngineInterface $templateEngine, $debug = false)
 {
     $this->templateEngine = $templateEngine;
     $this->debug = $debug;
     $exceptionHandler = new ExceptionHandler($templateEngine, $this->debug);
     set_exception_handler(array($exceptionHandler, 'handle'));
 }
Пример #17
0
 /**
  * Start the App.
  *
  * @return void
  */
 public function run()
 {
     //Define a custom error handler so we can log PHP errors
     set_error_handler(array('\\Kotori\\Core\\Handle', 'error'));
     set_exception_handler(array('\\Kotori\\Core\\Handle', 'exception'));
     register_shutdown_function(array('\\Kotori\\Core\\Handle', 'end'));
     Config::getSoul()->initialize($this->_config);
     ini_set('date.timezone', Config::getSoul()->TIME_ZONE);
     if (Config::getSoul()->USE_SESSION) {
         !session_id() && session_start();
     }
     //Build
     new Build(Config::getSoul()->APP_FULL_PATH);
     //Load application's common functions
     Helper::import(Config::getSoul()->APP_FULL_PATH . '/common.php');
     if (function_exists('spl_autoload_register')) {
         spl_autoload_register(array('\\Kotori\\Core\\Helper', 'autoload'));
     } else {
         function __autoload($className)
         {
             Helper::autoload($className);
         }
     }
     //Load route class
     Route::getSoul()->dispatch();
     //Global security filter
     array_walk_recursive($_GET, array('\\Kotori\\Http\\Request', 'filter'));
     array_walk_recursive($_POST, array('\\Kotori\\Http\\Request', 'filter'));
     array_walk_recursive($_REQUEST, array('\\Kotori\\Http\\Request', 'filter'));
 }
Пример #18
0
 /**
  * @param string   $model
  * @param string   $action
  * @param array    $params
  *
  * @throws RokCommon_Ajax_Exception
  * @return string
  */
 public static function run($model, $action, $params, $encoding = self::JSON_ENCODING)
 {
     // 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 {
         // get a model class instance
         $modelInstance = self::getModel($model);
         if ($encoding == self::JSON_ENCODING) {
             $decoded_params = json_decode($params);
             if (null == $decoded_params && strlen($params) > 0) {
                 throw new RokCommon_Ajax_Exception('Invalid JSON for params');
             }
             $params = $decoded_params;
         }
         // set the result to the run
         $result = $modelInstance->run($action, $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;
 }
Пример #19
0
 /**
  * Configures PHP error handling.
  * @return void
  */
 public static function setupErrors()
 {
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', TRUE);
     ini_set('html_errors', FALSE);
     ini_set('log_errors', FALSE);
     set_exception_handler(array(__CLASS__, 'handleException'));
     set_error_handler(function ($severity, $message, $file, $line) {
         if (in_array($severity, array(E_RECOVERABLE_ERROR, E_USER_ERROR), TRUE) || ($severity & error_reporting()) === $severity) {
             Environment::handleException(new \ErrorException($message, 0, $severity, $file, $line));
         }
         return FALSE;
     });
     register_shutdown_function(function () {
         Assert::$onFailure = array(__CLASS__, 'handleException');
         // note that Runner is unable to catch this errors in CLI & PHP 5.4.0 - 5.4.6 due PHP bug #62725
         $error = error_get_last();
         register_shutdown_function(function () use($error) {
             if (in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE), TRUE)) {
                 if (($error['type'] & error_reporting()) !== $error['type']) {
                     // show fatal errors hidden by @shutup
                     echo "\nFatal error: {$error['message']} in {$error['file']} on line {$error['line']}\n";
                 }
             } elseif (Environment::$checkAssertions && !Assert::$counter) {
                 echo "\nError: This test forgets to execute an assertion.\n";
                 exit(Runner\Job::CODE_FAIL);
             }
         });
     });
 }
Пример #20
0
 public function register()
 {
     ini_set('display_errors', false);
     set_exception_handler([$this, 'handleException']);
     set_error_handler([$this, 'handleError']);
     register_shutdown_function([$this, 'handleFatalError']);
 }
Пример #21
0
 /** called before any actions **/
 public function onBefore()
 {
     global $MONGO;
     //exception handler
     set_exception_handler(array($this, "exceptionHandler"));
     $this->_admin = MUser::userInSession();
     if (!$this->_admin) {
         //if user is loged in?
         $server = MServer::serverWithIndex(xi("host"));
         //filter server plugins
         if (class_exists("RFilter")) {
             RFilter::apply("SERVER_FILTER", $server);
         }
         //if auth is disabled
         if ($server && !$server->mongoAuth() && !$server->controlAuth()) {
             MUser::login("rockmongo_memo", "rockmongo_memo", xi("host"), "admin", 10800);
             $this->_admin = MUser::userInSession();
         } else {
             $this->redirect("login.index", array("host" => xi("host")));
         }
     }
     if (!$this->_admin->validate()) {
         $this->redirect("login.index", array("host" => $this->_admin->hostIndex()));
     }
     $this->_server = MServer::serverWithIndex($this->_admin->hostIndex());
     $this->_mongo = $this->_server->mongo();
     //log query
     if (isset($MONGO["features"]["log_query"]) && $MONGO["features"]["log_query"] == "on") {
         $this->_logQuery = true;
     }
     //render header
     if (!$this->isAjax()) {
         render_view("header");
     }
 }
Пример #22
0
 /**
  * Runs set_exception_handler function
  * Sets default error type for exceptions as E_ERROR
  */
 public function setExceptionHandler()
 {
     set_exception_handler(function ($e) {
         parent::$_controller->catchErrorAndHandle(array('Uncaught exception: ' . get_class($e), $e->getMessage(), $e->getFile(), $e->getLine(), parent::$_fileContent->getFileContent($e->getFile(), $e->getLine()), $this->getTrace($e), $e->getPrevious(), $e->getCode()));
         parent::$_controller->addReportedErrorCode(E_ERROR);
     });
 }
Пример #23
0
 public function __construct()
 {
     //turn on output buffering
     ob_start();
     //base path
     define('DIR', 'http://localhost/docstify/');
     //set default controller and method for legacy calls
     define('DEFAULT_CONTROLLER', 'welcome');
     define('DEFAULT_METHOD', 'index');
     //set the default template
     define('TEMPLATE', 'default');
     //set a default language
     define('LANGUAGE_CODE', 'es');
     //database details ONLY NEEDED IF USING A DATABASE
     define('DB_TYPE', 'mysql');
     define('DB_HOST', 'localhost');
     define('DB_NAME', 'dbname');
     define('DB_USER', 'root');
     define('DB_PASS', 'password');
     define('PREFIX', 'smvc_');
     //set prefix for sessions
     define('SESSION_PREFIX', '');
     //optionall create a constant for the name of the site
     define('SITETITLE', 'Docstify');
     //optionall set a site email address
     //define('SITEEMAIL', '');
     //turn on custom error handling
     set_exception_handler('Core\\Logger::ExceptionHandler');
     set_error_handler('Core\\Logger::ErrorHandler');
     //set timezone
     date_default_timezone_set('America/Mexico_City');
     //start sessions
     Session::init();
 }
Пример #24
0
 /**
  * Register the application exception handling
  *
  * @return void
  */
 public function register()
 {
     error_reporting(-1);
     set_error_handler([$this, 'handleError']);
     set_exception_handler([$this, 'handleUncaughtException']);
     register_shutdown_function([$this, 'handleShutdown']);
 }
Пример #25
0
 private function registerExceptionHandler($callPrevious = true)
 {
     $prev = set_exception_handler(array($this, 'handleException'));
     if ($callPrevious === true && $prev !== null) {
         $this->previousExceptionHandler = $prev;
     }
 }
Пример #26
0
 /**
  * Enable Kohana exception handling.
  *
  * @uses    Kohana_Exception::$template
  * @return  void
  */
 public static function enable()
 {
     if (!Kohana_Exception::$enabled) {
         set_exception_handler(array('Kohana_Exception', 'handle'));
         Kohana_Exception::$enabled = TRUE;
     }
 }
Пример #27
0
 /**
  * Init the logger depending on its context production, development or debug.
  *
  * @param string $context as production, development or debug, default is development
  * @return $this
  */
 public function setContext($context = 'development')
 {
     switch ($context) {
         case 'production':
             break;
         case 'development':
             error_reporting(-1);
             // Report all type of errors
             ini_set('display_errors', 1);
             // Display all errors
             ini_set('output_buffering', 0);
             // Do not buffer output
             set_exception_handler(function ($exception) {
                 echo "Anax: Uncaught exception: <p>" . $exception->getMessage() . "</p><pre>" . $exception->getTraceAsString() . "</pre>";
             });
             break;
         case 'debug':
             break;
         default:
             throw new Exception('Unknown context.');
             break;
     }
     $this->context = $context;
     return $this;
 }
Пример #28
0
 /**
  * @inheritdoc
  */
 protected function setUpExceptionHandler(SapiInterface $sapi, ContainerInterface $container)
 {
     error_reporting(E_ALL);
     $createHandler = function () use($container) {
         $has = $container->has(ExceptionHandlerInterface::class);
         $handler = $has === true ? $container->get(ExceptionHandlerInterface::class) : new DefaultHandler();
         return $handler;
     };
     $throwableHandler = function (Throwable $throwable) use($sapi, $container, $createHandler) {
         /** @var ExceptionHandlerInterface $handler */
         $handler = $createHandler();
         $handler->handleThrowable($throwable, $sapi, $container);
     };
     $exceptionHandler = function (Exception $exception) use($sapi, $container, $createHandler) {
         /** @var ExceptionHandlerInterface $handler */
         $handler = $createHandler();
         $handler->handleException($exception, $sapi, $container);
     };
     set_exception_handler(PHP_MAJOR_VERSION >= 7 ? $throwableHandler : $exceptionHandler);
     set_error_handler(function ($severity, $message, $fileName, $lineNumber) use($exceptionHandler) {
         $errorException = new ErrorException($message, 0, $severity, $fileName, $lineNumber);
         $exceptionHandler($errorException);
         throw $errorException;
     });
     // handle fatal error
     register_shutdown_function(function () use($container, $createHandler) {
         $error = error_get_last();
         if ($error !== null && (int) $error['type'] & (E_ERROR | E_COMPILE_ERROR)) {
             /** @var ExceptionHandlerInterface $handler */
             $handler = $createHandler();
             $handler->handleFatal($error, $container);
         }
     });
 }
 public function __construct()
 {
     $application_insights_options = get_option("applicationinsights_options");
     $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
     $this->_telemetryClient->getContext()->setInstrumentationKey($application_insights_options["instrumentation_key"]);
     set_exception_handler(array($this, 'exceptionHandler'));
 }
Пример #30
0
 public static function init($config = array(), $set_exception_handler = true, $set_error_handler = true, $report_fatal_errors = true)
 {
     // Heroku support
     // Use env vars for configuration, if set
     if (isset($_ENV['ROLLBAR_ACCESS_TOKEN']) && !isset($config['access_token'])) {
         $config['access_token'] = $_ENV['ROLLBAR_ACCESS_TOKEN'];
     }
     if (isset($_ENV['ROLLBAR_ENDPOINT']) && !isset($config['endpoint'])) {
         $config['endpoint'] = $_ENV['ROLLBAR_ENDPOINT'];
     }
     if (isset($_ENV['HEROKU_APP_DIR']) && !isset($config['root'])) {
         $config['root'] = $_ENV['HEROKU_APP_DIR'];
     }
     self::$instance = new RollbarNotifier($config);
     if ($set_exception_handler) {
         set_exception_handler('Rollbar::report_exception');
     }
     if ($set_error_handler) {
         set_error_handler('Rollbar::report_php_error');
     }
     if ($report_fatal_errors) {
         register_shutdown_function('Rollbar::report_fatal_error');
     }
     if (self::$instance->batched) {
         register_shutdown_function('Rollbar::flush');
     }
 }