Use the new abstract entity hook for user hooks

parent e0a4043f
......@@ -2,48 +2,9 @@
namespace Modules\User\Events;
use Modules\Core\Abstracts\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
final class UserIsCreating implements EntityIsChanging
final class UserIsCreating extends AbstractEntityHook implements EntityIsChanging
{
/**
* Contains the attributes which can be changed by other listeners
* @var array
*/
private $attributes;
/**
* Contains the original attributes which cannot be changed
* @var array
*/
private $original;
public function __construct(array $attributes)
{
$this->attributes = $attributes;
$this->original = $attributes;
}
/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param array $attributes
*/
public function setAttributes(array $attributes)
{
$this->attributes = array_replace_recursive($this->attributes, $attributes);
}
/**
* @return array
*/
public function getOriginal()
{
return $this->original;
}
}
......@@ -2,53 +2,21 @@
namespace Modules\User\Events;
use Modules\Core\Abstracts\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\User\Entities\UserInterface;
final class UserIsUpdating implements EntityIsChanging
final class UserIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var UserInterface
*/
private $user;
/**
* @var array
*/
private $attributes;
/**
* @var array
*/
private $original;
public function __construct(UserInterface $user, array $data)
{
$this->user = $user;
$this->attributes = $data;
$this->original = $data;
}
/**
* @return array
*/
public function getOriginal()
{
return $this->original;
}
/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param array $attributes
*/
public function setAttributes(array $attributes)
{
$this->attributes = array_replace_recursive($this->attributes, $attributes);
parent::__construct($data);
}
/**
......
......@@ -56,7 +56,7 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
]);
Event::assertDispatched(UserIsCreating::class, function ($e) use ($user) {
return $e->getAttributes()['email'] === $user->email;
return $e->getAttribute('email') === $user->email;
});
}
......@@ -104,7 +104,7 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
]);
Event::assertDispatched(UserIsCreating::class, function ($e) {
return $e->getOriginal()['email'] === 'n.widart@gmail.com';
return $e->getOriginal('email')=== 'n.widart@gmail.com';
});
}
......@@ -255,7 +255,7 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
Event::assertDispatched(UserIsUpdating::class, function ($e) use ($user) {
return $e->getUser()->id === $user->id &&
$e->getAttributes()['first_name'] === 'John';
$e->getAttribute('first_name') === 'John';
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment