1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Core\AccessToken\Command; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\AccessToken\AccessTokenId; |
17
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
18
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
19
|
|
|
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId; |
20
|
|
|
use OAuth2Framework\Component\Core\ResourceServer\ResourceServerId; |
21
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
22
|
|
|
|
23
|
|
|
class CreateAccessTokenCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var AccessTokenId |
27
|
|
|
*/ |
28
|
|
|
private $accessTokenId; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \DateTimeImmutable |
32
|
|
|
*/ |
33
|
|
|
private $expiresAt; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ClientId |
37
|
|
|
*/ |
38
|
|
|
private $clientId; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var UserAccountId |
42
|
|
|
*/ |
43
|
|
|
private $resourceOwnerId; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var DataBag |
47
|
|
|
*/ |
48
|
|
|
private $parameters; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var DataBag |
52
|
|
|
*/ |
53
|
|
|
private $metadatas; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var null|ResourceServerId |
57
|
|
|
*/ |
58
|
|
|
private $resourceServerId; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* CreateAccessTokenCommand constructor. |
62
|
|
|
* |
63
|
|
|
* @param AccessTokenId $accessTokenId |
64
|
|
|
* @param ClientId $clientId |
65
|
|
|
* @param ResourceOwnerId $resourceOwnerId |
66
|
|
|
* @param \DateTimeImmutable $expiresAt |
67
|
|
|
* @param DataBag $parameters |
68
|
|
|
* @param DataBag $metadatas |
69
|
|
|
* @param null|ResourceServerId $resourceServerId |
70
|
|
|
*/ |
71
|
|
|
protected function __construct(AccessTokenId $accessTokenId, ClientId $clientId, ResourceOwnerId $resourceOwnerId, \DateTimeImmutable $expiresAt, DataBag $parameters, DataBag $metadatas, ?ResourceServerId $resourceServerId) |
72
|
|
|
{ |
73
|
|
|
$this->accessTokenId = $accessTokenId; |
74
|
|
|
$this->clientId = $clientId; |
75
|
|
|
$this->resourceOwnerId = $resourceOwnerId; |
76
|
|
|
$this->expiresAt = $expiresAt; |
77
|
|
|
$this->parameters = $parameters; |
78
|
|
|
$this->metadatas = $metadatas; |
79
|
|
|
$this->resourceServerId = $resourceServerId; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param AccessTokenId $accessTokenId |
84
|
|
|
* @param ClientId $clientId |
85
|
|
|
* @param ResourceOwnerId $resourceOwnerId |
86
|
|
|
* @param \DateTimeImmutable $expiresAt |
87
|
|
|
* @param DataBag $parameters |
88
|
|
|
* @param DataBag $metadatas |
89
|
|
|
* @param null|ResourceServerId $resourceServerId |
90
|
|
|
* |
91
|
|
|
* @return CreateAccessTokenCommand |
|
|
|
|
92
|
|
|
*/ |
93
|
|
|
public static function create(AccessTokenId $accessTokenId, ClientId $clientId, ResourceOwnerId $resourceOwnerId, \DateTimeImmutable $expiresAt, DataBag $parameters, DataBag $metadatas, ?ResourceServerId $resourceServerId): self |
94
|
|
|
{ |
95
|
|
|
return new self($accessTokenId, $clientId, $resourceOwnerId, $expiresAt, $parameters, $metadatas, $resourceServerId); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return ClientId |
100
|
|
|
*/ |
101
|
|
|
public function getClientId(): ClientId |
102
|
|
|
{ |
103
|
|
|
return $this->clientId; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return ResourceOwnerId |
108
|
|
|
*/ |
109
|
|
|
public function getResourceOwnerId(): ResourceOwnerId |
110
|
|
|
{ |
111
|
|
|
return $this->resourceOwnerId; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return DataBag |
116
|
|
|
*/ |
117
|
|
|
public function getParameters(): DataBag |
118
|
|
|
{ |
119
|
|
|
return $this->parameters; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return DataBag |
124
|
|
|
*/ |
125
|
|
|
public function getMetadatas(): DataBag |
126
|
|
|
{ |
127
|
|
|
return $this->metadatas; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return null|ResourceServerId |
132
|
|
|
*/ |
133
|
|
|
public function getResourceServerId(): ?ResourceServerId |
134
|
|
|
{ |
135
|
|
|
return $this->resourceServerId; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return AccessTokenId |
140
|
|
|
*/ |
141
|
|
|
public function getAccessTokenId(): AccessTokenId |
142
|
|
|
{ |
143
|
|
|
return $this->accessTokenId; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return \DateTimeImmutable |
148
|
|
|
*/ |
149
|
|
|
public function getExpiresAt(): \DateTimeImmutable |
150
|
|
|
{ |
151
|
|
|
return $this->expiresAt; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.