Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
12424bca
Unverified
Commit
12424bca
authored
Jul 11, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the new abstract entity hook for user hooks
parent
e0a4043f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
79 deletions
+8
-79
UserIsCreating.php
Modules/User/Events/UserIsCreating.php
+2
-41
UserIsUpdating.php
Modules/User/Events/UserIsUpdating.php
+3
-35
SentinelUserRepositoryTest.php
Modules/User/Tests/SentinelUserRepositoryTest.php
+3
-3
No files found.
Modules/User/Events/UserIsCreating.php
View file @
12424bca
...
...
@@ -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
;
}
}
Modules/User/Events/UserIsUpdating.php
View file @
12424bca
...
...
@@ -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
);
}
/**
...
...
Modules/User/Tests/SentinelUserRepositoryTest.php
View file @
12424bca
...
...
@@ -56,7 +56,7 @@ class SentinelUserRepositoryTest extends BaseUserTestCase
]);
Event
::
assertDispatched
(
UserIsCreating
::
class
,
function
(
$e
)
use
(
$user
)
{
return
$e
->
getAttribute
s
()[
'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
->
getAttribute
s
()[
'first_name'
]
===
'John'
;
$e
->
getAttribute
(
'first_name'
)
===
'John'
;
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment