Failed Conditions
Push — master ( 7c3864...930f9b )
by Florent
14:15
created

AuthorizationRequest::getQueryParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\AuthorizationEndpoint\AuthorizationRequest;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseMode\ResponseMode;
17
use OAuth2Framework\Component\AuthorizationEndpoint\ResponseType\ResponseType;
18
use OAuth2Framework\Component\Core\Client\Client;
19
use OAuth2Framework\Component\Core\DataBag\DataBag;
20
use OAuth2Framework\Component\Core\ResourceServer\ResourceServer;
21
use OAuth2Framework\Component\Core\TokenType\TokenType;
22
use OAuth2Framework\Component\Core\User\User;
23
use OAuth2Framework\Component\Core\UserAccount\UserAccount;
24
25
class AuthorizationRequest
26
{
27
    /**
28
     * @var bool
29
     */
30
    private $authorized;
31
32
    /**
33
     * @var Client
34
     */
35
    private $client;
36
37
    /**
38
     * @var User|null
39
     */
40
    private $user = null;
41
42
    /**
43
     * @var UserAccount|null
44
     */
45
    private $userAccount = null;
46
47
    /**
48
     * @var DataBag
49
     */
50
    private $metadata;
51
52
    /**
53
     * @var TokenType|null
54
     */
55
    private $tokenType = null;
56
57
    /**
58
     * @var ResponseType]
59
     */
60
    private $responseType = null;
61
62
    /**
63
     * @var ResponseMode|null
64
     */
65
    private $responseMode = null;
66
67
    /**
68
     * @var array
69
     */
70
    private $queryParameters = [];
71
72
    /**
73
     * @var string|null
74
     */
75
    private $redirectUri = null;
76
77
    /**
78
     * @var array
79
     */
80
    private $consentScreenOptions = [];
81
82
    /**
83
     * @var array
84
     */
85
    private $responseParameters = [];
86
87
    /**
88
     * @var array
89
     */
90
    private $responseHeaders = [];
91
92
    /**
93
     * @var null|ResourceServer
94
     */
95
    private $resourceServer = null;
96
97
    public function __construct(Client $client, array $queryParameters)
98
    {
99
        $this->client = $client;
100
        $this->queryParameters = $queryParameters;
101
        $this->metadata = new DataBag([]);
102
    }
103
104
    public function getQueryParams(): array
105
    {
106
        return $this->queryParameters;
107
    }
108
109
    public function hasQueryParam(string $param): bool
110
    {
111
        return \array_key_exists($param, $this->queryParameters);
112
    }
113
114
    public function getQueryParam(string $param)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
115
    {
116
        if (!$this->hasQueryParam($param)) {
117
            throw new \InvalidArgumentException(\Safe\sprintf('Invalid parameter "%s".', $param));
118
        }
119
120
        return $this->queryParameters[$param];
121
    }
122
123
    public function getClient(): Client
124
    {
125
        return $this->client;
126
    }
127
128
    public function setTokenType(TokenType $tokenType): void
129
    {
130
        $this->tokenType = $tokenType;
131
    }
132
133
    public function getTokenType(): ?TokenType
134
    {
135
        return $this->tokenType;
136
    }
137
138
    public function setResponseType(ResponseType $responseType): void
139
    {
140
        $this->responseType = $responseType;
141
    }
142
143
    public function getResponseType(): ResponseType
144
    {
145
        return $this->responseType;
146
    }
147
148
    public function setResponseMode(ResponseMode $responseMode): void
149
    {
150
        $this->responseMode = $responseMode;
151
    }
152
153
    public function getResponseMode(): ?ResponseMode
154
    {
155
        return $this->responseMode;
156
    }
157
158
    public function setRedirectUri(string $redirectUri): void
159
    {
160
        $this->redirectUri = $redirectUri;
161
    }
162
163
    public function getRedirectUri(): ?string
164
    {
165
        return $this->redirectUri;
166
    }
167
168
    public function setUser(User $user): void
169
    {
170
        $this->user = $user;
171
    }
172
173
    public function getUser(): ?User
174
    {
175
        return $this->user;
176
    }
177
178
    public function setUserAccount(UserAccount $userAccount): void
179
    {
180
        $this->userAccount = $userAccount;
181
    }
182
183
    public function getUserAccount(): ?UserAccount
184
    {
185
        return $this->userAccount;
186
    }
187
188
    public function setResponseParameter(string $responseParameter, $value): void
189
    {
190
        $this->responseParameters[$responseParameter] = $value;
191
    }
192
193
    public function getResponseParameters(): array
194
    {
195
        return $this->responseParameters;
196
    }
197
198
    public function getResponseParameter(string $param)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
199
    {
200
        if (!$this->hasResponseParameter($param)) {
201
            throw new \InvalidArgumentException(\Safe\sprintf('Invalid response parameter "%s".', $param));
202
        }
203
204
        return $this->getResponseParameters()[$param];
205
    }
206
207
    public function hasResponseParameter(string $param): bool
208
    {
209
        return \array_key_exists($param, $this->getResponseParameters());
210
    }
211
212
    public function setResponseHeader(string $responseHeader, $value): void
213
    {
214
        $this->responseHeaders[$responseHeader] = $value;
215
    }
216
217
    public function getResponseHeaders(): array
218
    {
219
        return $this->responseHeaders;
220
    }
221
222
    /**
223
     * @return string[]
224
     */
225
    public function getPrompt(): array
226
    {
227
        if (!$this->hasQueryParam('prompt')) {
228
            return [];
229
        }
230
231
        return \explode(' ', $this->getQueryParam('prompt'));
232
    }
233
234
    public function hasUiLocales(): bool
235
    {
236
        return $this->hasQueryParam('ui_locales');
237
    }
238
239
    /**
240
     * @return string[]
241
     */
242
    public function getUiLocales(): array
243
    {
244
        return $this->hasQueryParam('ui_locales') ? \explode(' ', $this->getQueryParam('ui_locales')) : [];
245
    }
246
247
    public function hasPrompt(string $prompt): bool
248
    {
249
        return \in_array($prompt, $this->getPrompt(), true);
250
    }
251
252
    public function isAuthorized(): bool
253
    {
254
        return $this->authorized;
255
    }
256
257
    public function allow(): void
258
    {
259
        $this->authorized = true;
260
    }
261
262
    public function deny(): void
263
    {
264
        $this->authorized = false;
265
    }
266
267
    public function getResourceServer(): ?ResourceServer
268
    {
269
        return $this->resourceServer;
270
    }
271
272
    public function setResourceServer(ResourceServer $resourceServer): void
273
    {
274
        $this->resourceServer = $resourceServer;
275
    }
276
277
    public function setConsentScreenOption(string $option, $value): void
278
    {
279
        $this->consentScreenOptions[$option] = $value;
280
    }
281
282
    public function hasScope(): bool
283
    {
284
        return $this->hasQueryParam('scope');
285
    }
286
287
    public function getScope(): string
288
    {
289
        return $this->getQueryParam('scope');
290
    }
291
292
    public function getMetadata(): DataBag
293
    {
294
        return $this->metadata;
295
    }
296
}
297