1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LineMob\Core\Mocky; |
4
|
|
|
|
5
|
|
|
use LineMob\Core\Middleware\ClearActiveCmdMiddleware; |
6
|
|
|
use LineMob\Core\Middleware\CommandSwitcherMiddleware; |
7
|
|
|
use LineMob\Core\Middleware\DummyFallbackMiddleware; |
8
|
|
|
use LineMob\Core\Middleware\DumpLogMiddleware; |
9
|
|
|
use LineMob\Core\Middleware\StoreActiveCmdMiddleware; |
10
|
|
|
use LineMob\Core\Mocky\Auth\AuthenticationWorkflow; |
11
|
|
|
use LineMob\Core\Mocky\Auth\Command\ClearActiveCommand; |
12
|
|
|
use LineMob\Core\Mocky\Auth\Command\LoginCommand; |
13
|
|
|
use LineMob\Core\Mocky\Auth\Command\LogoutCommand; |
14
|
|
|
use LineMob\Core\Mocky\Auth\Command\NonSecuredCommand; |
15
|
|
|
use LineMob\Core\Mocky\Auth\Command\SecuredCommand; |
16
|
|
|
use LineMob\Core\Mocky\Auth\Middleware\AuthenticationMiddleware; |
17
|
|
|
use LineMob\Core\Mocky\Auth\Middleware\AuthorizationMiddleware; |
18
|
|
|
use LineMob\Core\Mocky\Auth\Middleware\ClearActiveMiddleware; |
19
|
|
|
use LineMob\Core\Mocky\Auth\Middleware\LogoutMiddleware; |
20
|
|
|
use LineMob\Core\Mocky\Doctrine\Model\User; |
21
|
|
|
use LineMob\Core\Mocky\Doctrine\StorageConnectMiddleware; |
22
|
|
|
use LineMob\Core\Mocky\Doctrine\StoragePersistMiddleware; |
23
|
|
|
use LineMob\Core\Mocky\Switcher\SomeCommand; |
24
|
|
|
use LineMob\Core\Mocky\Switcher\SwitchedCommand; |
25
|
|
|
use LineMob\Core\Mocky\Switcher\SwitchingMiddleware; |
26
|
|
|
use LineMob\Core\QuickStart; |
27
|
|
|
use Symfony\Component\Workflow\Registry as WorkflowRegistry; |
28
|
|
|
|
29
|
|
|
class Setup |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param array $data |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public static function switching(array $data) |
37
|
|
|
{ |
38
|
|
|
return (new QuickStart( |
39
|
|
|
[ |
40
|
|
|
new SwitchingMiddleware(), |
41
|
|
|
new CommandSwitcherMiddleware(), |
42
|
|
|
new DummyFallbackMiddleware(), |
43
|
|
|
new DumpLogMiddleware(true), |
44
|
|
|
] |
45
|
|
|
)) |
46
|
|
|
->addCommand(SomeCommand::class, true) |
47
|
|
|
->addCommand(SwitchedCommand::class) |
48
|
|
|
->setup(null, null, [], new Sender()) |
49
|
|
|
->handle(json_encode($data)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $data |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public static function authen(array $data) |
58
|
|
|
{ |
59
|
|
|
$workflowRegistry = new WorkflowRegistry(); |
60
|
|
|
$workflowRegistry->add((new AuthenticationWorkflow())->create(), User::class); |
61
|
|
|
|
62
|
|
|
return (new QuickStart( |
63
|
|
|
[ |
64
|
|
|
new StorageConnectMiddleware(), |
65
|
|
|
new ClearActiveMiddleware(), // Clear user's storage active |
66
|
|
|
new LogoutMiddleware(), |
67
|
|
|
new AuthorizationMiddleware(), |
68
|
|
|
new CommandSwitcherMiddleware(), |
69
|
|
|
new AuthenticationMiddleware($workflowRegistry), |
70
|
|
|
new DummyFallbackMiddleware(), |
71
|
|
|
new StoreActiveCmdMiddleware(), |
72
|
|
|
new StoragePersistMiddleware(), |
73
|
|
|
new DumpLogMiddleware(true), |
74
|
|
|
] |
75
|
|
|
)) |
76
|
|
|
->addCommand(NonSecuredCommand::class, true) |
77
|
|
|
->addCommand(ClearActiveCommand::class) |
78
|
|
|
->addCommand(SecuredCommand::class) |
79
|
|
|
->addCommand(LoginCommand::class) |
80
|
|
|
->addCommand(LogoutCommand::class) |
81
|
|
|
->setup(null, null, [], new Sender()) |
82
|
|
|
->handle(json_encode($data)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|