|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\User\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\User\Tasks\CreateUserTask; |
|
6
|
|
|
use App\Containers\User\Tasks\FindUserTask; |
|
7
|
|
|
use App\Port\Action\Abstracts\Action; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class CreateVisitorUserAction. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class CreateVisitorUserAction extends Action |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \App\Containers\User\Actions\CreateUserTask |
|
19
|
|
|
*/ |
|
20
|
|
|
private $createUserTask; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \App\Containers\User\Tasks\FindUserTask |
|
24
|
|
|
*/ |
|
25
|
|
|
private $findUserTask; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* CreateUserAction constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \App\Containers\User\Tasks\CreateUserTask $createUserTask |
|
31
|
|
|
* @param \App\Containers\User\Tasks\FindUserTask $findUserTask |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(CreateUserTask $createUserTask, FindUserTask $findUserTask) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->createUserTask = $createUserTask; |
|
|
|
|
|
|
36
|
|
|
$this->findUserTask = $findUserTask; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* This is to be used only by a Middleware, it is a way to store records about the user |
|
41
|
|
|
* even before he registers. Very helpful for Mobile apps that doesn't require a user to |
|
42
|
|
|
* register and login before using the app. |
|
43
|
|
|
* Then when the user decided to register (to use some extra features) the `UpdateVisitorUserAction` |
|
44
|
|
|
* Action will be used to update the already created user (user will be determined by his Device ID). |
|
45
|
|
|
* |
|
46
|
|
|
* @param $visitorId |
|
47
|
|
|
* @param null $platform |
|
48
|
|
|
* @param null $device |
|
49
|
|
|
* @param bool|false $login |
|
|
|
|
|
|
50
|
|
|
* |
|
51
|
|
|
* @return mixed |
|
52
|
|
|
*/ |
|
53
|
|
|
public function run($visitorId, $device = null, $platform = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$user = $this->findUserTask->byVisitorId($visitorId); |
|
56
|
|
|
|
|
57
|
|
|
if(!$user){ |
|
58
|
|
|
$user = $this->createUserTask->byVisitor($visitorId, $device, $platform); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $user; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
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..