Created
June 25, 2018 13:51
-
-
Save tsukasa-mixer/3aa9c5e864b4b8e3aa4d96c0bab45c1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace \Application\Exception | |
class CustomException extends RuntimeException | |
{ | |
private $backLink; | |
public $defaultMessage = 'Произошла ошибка выполнения скрипта, попробуйте повторить запрос позже'; | |
public function __construct($message = '', $code = 0, Throwable $previous = null) | |
{ | |
parent::__construct($message ?: $this->message, $code, $previous); | |
} | |
public function setBackLink($link, $text = '') | |
{ | |
if ($link && is_bool($link)) { | |
$link = 'javascript:window.history.go(-1); return false;'; | |
} | |
$this->backLink = [$link, $text ?: tr('Вернутся назад', 'Common')]; | |
} | |
public function getHtml() | |
{ | |
$message = $this->getMessage(); | |
if ($this->backLink) { | |
$message .= "<a href='{$this->backLink[0]}' class='message__back'>" . $this->backLink[1] . '</a>'; | |
} | |
return "<div class='error message'>{$message}</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
я б не стал нагружать функционалом отображения сообщений, пусть об этом думает функционал который будет отлавливать))