Completed
Push — master ( 0305e0...445b0e )
by Neomerx
02:25
created

AuthorizationException::getExtraParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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