本文整理汇总了PHP中set_exception_handler函数的典型用法代码示例。如果您正苦于以下问题:PHP set_exception_handler函数的具体用法?PHP set_exception_handler怎么用?PHP set_exception_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_exception_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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: run
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: testConsoleEvent
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());
}
示例4: testStacking
/**
* @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: run
/**
+----------------------------------------------------------
* 应用程序初始化
+----------------------------------------------------------
* @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: onBootstrap
/**
* 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: __construct
/**
* @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: __construct
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: enable
/**
* 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: __construct
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: init
/**
* 环境初始化
* @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: testNotice
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: init
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: __construct
/**
* 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'));
}
示例15: init
static function init()
{
set_exception_handler("MVCCore::exception");
set_error_handler("MVCCore::error");
register_shutdown_function("MVCCore::shutdown");
spl_autoload_register("MVCCore::autoload");
}