本文整理汇总了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();
}
}
示例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);