1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Application\Exceptions; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2020 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Contracts\Exceptions\AuthorizationExceptionInterface; |
22
|
|
|
use RuntimeException; |
23
|
|
|
use function assert; |
24
|
|
|
use function is_int; |
25
|
|
|
use function is_string; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @package Limoncello\Application |
29
|
|
|
*/ |
30
|
|
|
class AuthorizationException extends RuntimeException implements AuthorizationExceptionInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $action; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string|null |
39
|
|
|
*/ |
40
|
|
|
private $resourceType; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string|int|null |
44
|
|
|
*/ |
45
|
|
|
private $resourceIdentity; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $extraParameters; |
51
|
|
|
|
52
|
|
|
/** |
53
|
1 |
|
* @param string $action |
54
|
|
|
* @param null|string $resourceType |
55
|
|
|
* @param int|null|string $resourceIdentity |
56
|
|
|
* @param array $extraParams |
57
|
|
|
*/ |
58
|
|
|
public function __construct( |
59
|
1 |
|
string $action, |
60
|
|
|
string $resourceType = null, |
61
|
1 |
|
$resourceIdentity = null, |
62
|
1 |
|
array $extraParams = [] |
63
|
1 |
|
) { |
64
|
1 |
|
assert($resourceIdentity === null || is_string($resourceIdentity) || is_int($resourceIdentity)); |
65
|
|
|
|
66
|
|
|
$this->action = $action; |
67
|
|
|
$this->resourceType = $resourceType; |
68
|
|
|
$this->resourceIdentity = $resourceIdentity; |
69
|
|
|
$this->extraParameters = $extraParams; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
|
|
public function getAction(): string |
76
|
|
|
{ |
77
|
|
|
return $this->action; |
78
|
1 |
|
} |
79
|
|
|
|
80
|
1 |
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
|
|
public function getResourceType(): ?string |
84
|
|
|
{ |
85
|
|
|
return $this->resourceType; |
86
|
1 |
|
} |
87
|
|
|
|
88
|
1 |
|
/** |
89
|
|
|
* @inheritdoc |
90
|
|
|
*/ |
91
|
|
|
public function getResourceIdentity() |
92
|
|
|
{ |
93
|
|
|
return $this->resourceIdentity; |
94
|
1 |
|
} |
95
|
|
|
|
96
|
1 |
|
/** |
97
|
|
|
* @inheritdoc |
98
|
|
|
*/ |
99
|
|
|
public function getExtraParameters(): array |
100
|
|
|
{ |
101
|
|
|
return $this->extraParameters; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|