コード例 #1
0
ファイル: App.php プロジェクト: Shareed2k/mvc_demo
 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();
     }
 }
コード例 #2
0
        $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('*****@*****.**', '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);