申博娱乐’s的默认错误和异常处理程序比默认的php处理程序提供更多信息,因为它们会打印出 基本的 回溯,而不是只打印出错误的文件和行号,但是当申博娱乐出现很多次时’s handlers just don’切需要查看完全扩展的变量的次数,这些变量将传递到回溯中的函数/方法。
在里面 申博娱乐初始安装开发技巧 博客文章中,我写了有关Xdebug如何使用详细的,可自定义的错误回溯来覆盖默认的php错误处理程序的信息。我解释了如何修改申博娱乐’的核心代码,以便由Xdebug(而非申博娱乐)处理php错误’s default 错误 处理程序。
在这篇博客中,我’我将解释如何修改申博娱乐,以便Xdebug而非申博娱乐处理异常’s default例外 处理程序。
Mage :: 跑()方法是启动整个申博娱乐请求周期的方法,因此在这里处理异常是有意义的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/ ** *前端主要入口点 * * @参数字符串$ 码 * @参数字符串$ 类型 * @param string |数组$ 选项 * / 上市 静态的 功能 跑($码 = '', $类型 = '商店', $选项=<a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>()) { 尝试 { Varien_Profiler::开始(法师); 自::setRoot(); 自::$_app = 新 Mage_Core_Model_App(); 自::$_事件 = 新 Varien_Event_Collection (); 自::$_config = 新 Mage_Core_Model_Config(); 自::$_app->跑(<a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>( 'scope_code' => $码, 'scope_type' => $类型, '选项' => $选项, )); Varien_Profiler::停(法师); } 抓住 (Mage_Core_Model_Session_例外 $e) { <a href="http://www.php.net/header" 目标=“_空白” rel=“ noopener”>标头</a>('位置: ' . 自::getBaseUrl()); <a href="http://www.php.net/die" 目标=“_空白” rel=“ noopener”>死</a>(); } 抓住 (Mage_Core_Model_Store_例外 $e) { require_once(自::getBaseDir() . DS . “错误” . DS . '404.php'); <a href="http://www.php.net/die" 目标=“_空白” rel=“ noopener”>死</a>(); } 抓住 (例外 $e) { 如果 (自::已安装() || 自::$_isDownloader) { 自::printException($e); <a href="http://www.php.net/exit" 目标=“_空白” rel=“ noopener”>出口</a>(); } 尝试 { 自::dispatchEvent('mage_run_exception', <a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>('例外' => $e)); 如果 (!<a href="http://www.php.net/headers_sent" 目标=“_空白” rel=“ noopener”>标头s_sent</a>()) { <a href="http://www.php.net/header" 目标=“_空白” rel=“ noopener”>标头</a>('位置:' . 自::getUrl('安装')); } 其他 { 自::printException($e); } } 抓住 (例外 $NE) { 自::printException($NE, $e->getMessage()); } } } |
上面的代码的问题是,任何申博娱乐代码引发的任何异常都由Mage :: printException()方法处理。如果从index.php启用了开发人员模式,我们需要做的是运行基本代码而不将其包装在任何try / 抓住块中。这将导致Xdebug异常处理程序处理所有异常。这是结果代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
/ ** *前端主要入口点 * * @参数字符串$ 码 * @参数字符串$ 类型 * @param string |数组$ 选项 * / 上市 静态的 功能 跑($码 = '', $类型 = '商店', $选项=<a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>()) { 如果(!自::getIsDeveloperMode()){ 尝试 { Varien_Profiler::开始(法师); 自::setRoot(); 自::$_app = 新 Mage_Core_Model_App(); 自::$_事件 = 新 Varien_Event_Collection (); 自::$_config = 新 Mage_Core_Model_Config(); 自::$_app->跑(<a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>( 'scope_code' => $码, 'scope_type' => $类型, '选项' => $选项, )); Varien_Profiler::停(法师); } 抓住 (Mage_Core_Model_Session_例外 $e) { <a href="http://www.php.net/header" 目标=“_空白” rel=“ noopener”>标头</a>('位置: ' . 自::getBaseUrl()); <a href="http://www.php.net/die" 目标=“_空白” rel=“ noopener”>死</a>(); } 抓住 (Mage_Core_Model_Store_例外 $e) { require_once(自::getBaseDir() . DS . “错误” . DS . '404.php'); <a href="http://www.php.net/die" 目标=“_空白” rel=“ noopener”>死</a>(); } 抓住 (例外 $e) { 如果 (自::已安装() || 自::$_isDownloader) { 自::printException($e); <a href="http://www.php.net/exit" 目标=“_空白” rel=“ noopener”>出口</a>(); } 尝试 { 自::dispatchEvent('mage_run_exception', <a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>('例外' => $e)); 如果 (!<a href="http://www.php.net/headers_sent" 目标=“_空白” rel=“ noopener”>标头s_sent</a>()) { <a href="http://www.php.net/header" 目标=“_空白” rel=“ noopener”>标头</a>('位置:' . 自::getUrl('安装')); } 其他 { 自::printException($e); } } 抓住 (例外 $NE) { 自::printException($NE, $e->getMessage()); } } } 其他 { //如果我们以开发人员模式运行,我们希望所有异常都由php | xdebug错误处理程序处理 Varien_Profiler::开始(法师); 自::setRoot(); 自::$_app = 新 Mage_Core_Model_App(); 自::$_事件 = 新 Varien_Event_Collection (); 自::$_config = 新 Mage_Core_Model_Config(); 自::$_app->跑(<a href="http://www.php.net/array" 目标=“_空白” rel=“ noopener”>数组</a>( 'scope_code' => $码, 'scope_type' => $类型, '选项' => $选项, )); Varien_Profiler::停(法师); } } |
此代码允许Xdebug’的异常处理程序可以发挥其魔力,从而产生完全详细的异常回溯,如下所示:
希望这个小技巧可以使您更有效地编码申博娱乐!