Passed
Push — master ( 67aa31...d47bdf )
by Kirill
03:20
created

AuthContext::getToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Auth;
13
14
final class AuthContext implements AuthContextInterface
15
{
16
    /** @var ActorProviderInterface */
17
    private $actorProvider;
18
19
    /** @var TokenInterface|null */
20
    private $token;
21
22
    /** @var object|null */
23
    private $actor;
24
25
    /** @var string|null */
26
    private $transport;
27
28
    /** @var bool */
29
    private $closed = false;
30
31
    /**
32
     * @param ActorProviderInterface $actorProvider
33
     */
34
    public function __construct(ActorProviderInterface $actorProvider)
35
    {
36
        $this->actorProvider = $actorProvider;
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function start(TokenInterface $token, string $transport = null): void
43
    {
44
        $this->closed = false;
45
        $this->actor = null;
46
        $this->token = $token;
47
        $this->transport = $transport;
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function getToken(): ?TokenInterface
54
    {
55
        return $this->token;
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function getTransport(): ?string
62
    {
63
        return $this->transport;
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function getActor(): ?object
70
    {
71
        if ($this->closed) {
72
            return null;
73
        }
74
75
        if ($this->actor === null && $this->token !== null) {
76
            $this->actor = $this->actorProvider->getActor($this->token);
77
        }
78
79
        return $this->actor;
80
    }
81
82
    /**
83
     * @inheritDoc
84
     */
85
    public function close(): void
86
    {
87
        $this->closed = true;
88
        $this->actor = null;
89
    }
90
91
    /**
92
     * @inheritDoc
93
     */
94
    public function isClosed(): bool
95
    {
96
        return $this->closed;
97
    }
98
}
99