Как остановить выполнение кода, если обработчик события возвращает false в yii2

Я пытаюсь создать модуль в yii2. Я хочу использовать события для обработки некоторых событий в моем модуле и сделать мой модуль независимым от моего ядра.

Теперь я хочу остановить поток кода модуля, если событие и даже обработчик возвращают false.

Посмотрите код ниже:

function withdraw($amount, $description = null)
{
if (!(is_integer($amount) or is_float($amount) or is_double($amount))) {
throw new InvalidArgumentException("Amount should be in double.");
}
try {
$event = new TransactionEvent();
$event->setTransaction($transactionModel);
$event->setType($event::TYPE_WITHDRAW);
$this->trigger(\aminkt\userAccounting\UserAccounting::EVENT_WITHDRAW, $event);

$this->totalWithdraw += $amount;
if (!$this->save())
throw new RuntimeException("Purse cant update itself in withdraw action.");

$transaction->commit();
} catch (\Exception $e) {
throw $e;
} catch (\Throwable $e) {
throw $e;
}
}

Это мой код сейчас. Я хочу, чтобы что-то ниже знало, что обработчик событий работает правильно, и моя транзакция правильно сохранена в базе данных:

if($this->trigger(\aminkt\userAccounting\UserAccounting::EVENT_WITHDRAW, event)){
$this->totalWithdraw += $amount;
if (!$this->save())
throw new RuntimeException("Purse cant update itself in withdraw action.");
}else{
throw new RuntimeException("Transaction handler not worked correctly.");
}

Спасибо.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector