Система управления «Сайт PRO»
Версия 20240107

Класс Error

Объект $Error: Cms\Root\Error наследует Exception

Объект «Ошибка»

Исходный код
class Error extends \Exception { … }

Свойства

$messages

$Error->messages = array();

Сообщения

Исходный код
    var $messages = array();

Методы

__construct()

new Error($error);

Конструктор

Параметры:

ИмяОписание
$error

Ошибка

Исходный код
    function __construct($error) {
        if (is_array($error)) {
            parent::__construct(array_shift($error));
            $this->addError($error);
        } else {
            parent::__construct($error);
        }
    }

__toString()

$Error->__toString();

В виде строки

Возвращает: string

Исходный код
    function __toString() {
        if (count($this->messages)) return implode("\n", $this->messages);
        else return $this->getMessage();
    }

getError()

$Error->getError();

Получить ошибку

Возвращает: Cms\Root\Error

Исходный код
    function getError() {
        return $this;
    }

setError()

$Error->setError($error);

Установить ошибку

Параметры:

ИмяОписание
$error

Cms\Root\Error; string Ошибка

Возвращает: Cms\Root\Error

Исходный код
    function setError($error) {
        if ($this !== $error) $this->messages = is_array($error) ? $error : array($error);
        else $this->messages = array();
        return $this;
    }

addError()

$Error->addError($error);

Добавить ошибку

Параметры:

ИмяОписание
$error

Cms\Root\Error; string Ошибка

Возвращает: Cms\Root\Error

Исходный код
    function addError($error) {
        if (!count($this->messages)) $this->messages[] = $this->getError()->__toString();
        if (is_array($error)) foreach ($error as $e) {
            if ($this !== $e) $this->messages[] = $e;
        } else {
            if ($this !== $error) $this->messages[] = $error;
        }
        return $this;
    }