当前位置: 首页>>代码示例>>PHP>>正文


PHP ExceptionHandler::attach方法代码示例

本文整理汇总了PHP中ExceptionHandler::attach方法的典型用法代码示例。如果您正苦于以下问题:PHP ExceptionHandler::attach方法的具体用法?PHP ExceptionHandler::attach怎么用?PHP ExceptionHandler::attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExceptionHandler的用法示例。


在下文中一共展示了ExceptionHandler::attach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct()
 {
     $this->createCsrfToken();
     // Create the ExceptionHandler
     $handler = new ExceptionHandler();
     // Attach an Exception Logger
     $handler->attach(new Logger());
     // Set ExceptionHandler::handle() as the default
     set_exception_handler(array($handler, 'handle'));
     try {
         $url = $this->parseUrl();
         // TODO make actions listen to specific requests
         $request_type = strtolower($_SERVER['REQUEST_METHOD']);
         if (isset($url[0])) {
             $url[0] = $this->namespace . '\\' . ucfirst($url[0] .= 'Controller');
             if (class_exists($url[0])) {
                 $this->controller = $url[0];
             } else {
                 $this->method = 'errorAction';
             }
             unset($url[0]);
         }
         $this->controller = new $this->controller();
         if (isset($url[1])) {
             if (method_exists($this->controller, $url[1] .= 'Action')) {
                 $this->method = $url[1];
             } else {
                 $this->method = 'errorAction';
             }
             unset($url[1]);
         }
         $this->params = $url ? array_values($url) : [];
         call_user_func_array([$this->controller, $this->method], $this->params);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
开发者ID:Shareed2k,项目名称:mvc_demo,代码行数:37,代码来源:App.php

示例2: phpversion

        $output .= 'Stack Trace:' . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
        $headers = 'From: webmaster@yourdomain.com' . "\r\n" . 'Reply-To: webmaster@yourdomain.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
        echo "\n\nThe following email (would be) sent to your webmaster@yourdomain.com:\n\n";
        echo $output;
        //return mail('webmaster@yourdomain.com', 'Exception Thrown', $output, $headers);
    }
}
/**
 * Assume this Mailer class is your actual mailer class (i.e. SwiftMailer).
 */
class Mailer
{
}
/**
 * Assume this Logger class is your actual logger class.
 */
class Logger
{
}
//====================================
// BELOW THIS LINE RUNS THE ABOVE CODE
//====================================
// Create the ExceptionHandler
$handler = new ExceptionHandler();
// Attach an Exception Logger and Mailer
$handler->attach(new ExceptionLogger());
$handler->attach(new ExceptionMailer());
// Set ExceptionHandler::handle() as the default
set_exception_handler(array($handler, 'handle'));
// throw an exception for handling
throw new Exception("This is a test of the emergency broadcast system\n", 0);
开发者ID:pixlr,项目名称:ZCE-PHP-Cert,代码行数:31,代码来源:observer-exception-handler.php


注:本文中的ExceptionHandler::attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。