|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\User\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\User\Events\Events\UserCreatedEvent; |
|
6
|
|
|
use App\Containers\User\Services\CreateUserService; |
|
7
|
|
|
use App\Port\Action\Abstracts\Action; |
|
8
|
|
|
use App\Port\Event\Dispatcher\EventsDispatcher; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class CreateUserWithCredentialsAction. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class CreateUserWithCredentialsAction extends Action |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var \App\Containers\User\Actions\CreateUserService |
|
20
|
|
|
*/ |
|
21
|
|
|
private $createUserService; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var \App\Port\Event\Dispatcher\EventsDispatcher |
|
25
|
|
|
*/ |
|
26
|
|
|
private $eventsDispatcher; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* CreateUserWithCredentialsAction constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \App\Containers\User\Services\CreateUserService $createUserService |
|
32
|
|
|
* @param \App\Port\Event\Dispatcher\EventsDispatcher $eventsDispatcher |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(CreateUserService $createUserService, EventsDispatcher $eventsDispatcher) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->createUserService = $createUserService; |
|
|
|
|
|
|
37
|
|
|
$this->eventsDispatcher = $eventsDispatcher; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* create a new user object. |
|
42
|
|
|
* optionally can login the created user and return it with its token. |
|
43
|
|
|
* |
|
44
|
|
|
* @param $email |
|
45
|
|
|
* @param $password |
|
46
|
|
|
* @param $name |
|
47
|
|
|
* @param bool $login determine weather to login or not after creating |
|
48
|
|
|
* |
|
49
|
|
|
* @return mixed |
|
50
|
|
|
*/ |
|
51
|
|
|
public function run($email, $password, $name, $login = false) |
|
52
|
|
|
{ |
|
53
|
|
|
$user = $this->createUserService->byCredentials($email, $password, $name, $login); |
|
54
|
|
|
|
|
55
|
|
|
// Fire a User Created Event |
|
56
|
|
|
$this->eventsDispatcher->fire(New UserCreatedEvent($user)); |
|
57
|
|
|
|
|
58
|
|
|
return $user; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..