Completed
Push — master ( a40390...c25130 )
by
11s
created

Setup::authen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

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