From 4341d2173ba472642ea64f94e764a18d02dc35e4 Mon Sep 17 00:00:00 2001 From: Alec Pritchard Date: Thu, 8 Feb 2018 17:17:16 +0000 Subject: [PATCH 1/2] Bugfix for Model events UserEvent::EVENT_BEFORE_CONFIRMATION and UserEvent::EVENT_AFTER_CONFIRMATION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bugfix for Model events UserEvent::EVENT_BEFORE_CREATE and UserEvent:… … …:EVENT_AFTER_CREATE Feed instance of Da\User\Event\UserEvent to resolve error in event handlers: TypeError Argument 1 passed to {closure}() must be an instance of Da\User\Event\UserEvent, instance of yii\base\Event given --- src/User/Service/UserConfirmationService.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/User/Service/UserConfirmationService.php b/src/User/Service/UserConfirmationService.php index f0715b8..5958080 100644 --- a/src/User/Service/UserConfirmationService.php +++ b/src/User/Service/UserConfirmationService.php @@ -26,9 +26,12 @@ class UserConfirmationService implements ServiceInterface public function run() { - $this->model->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION); + $model = $this->model; + $event = $this->make(UserEvent::class, [$model]); + + $this->model->trigger(UserEvent::EVENT_BEFORE_CONFIRMATION, $event); if ((bool)$this->model->updateAttributes(['confirmed_at' => time()])) { - $this->model->trigger(UserEvent::EVENT_AFTER_CONFIRMATION); + $this->model->trigger(UserEvent::EVENT_AFTER_CONFIRMATION, $event); return true; } From b8233114f8f992c69b3e798277ac4b9691f163d3 Mon Sep 17 00:00:00 2001 From: Alec Pritchard Date: Fri, 9 Feb 2018 09:34:01 +0000 Subject: [PATCH 2/2] Added `use MailAwareTrait;` --- src/User/Service/UserConfirmationService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/User/Service/UserConfirmationService.php b/src/User/Service/UserConfirmationService.php index 5958080..aa18f4b 100644 --- a/src/User/Service/UserConfirmationService.php +++ b/src/User/Service/UserConfirmationService.php @@ -14,9 +14,12 @@ namespace Da\User\Service; use Da\User\Contracts\ServiceInterface; use Da\User\Event\UserEvent; use Da\User\Model\User; +use Da\User\Traits\MailAwareTrait; class UserConfirmationService implements ServiceInterface { + use MailAwareTrait; + protected $model; public function __construct(User $model)