1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Platine OAuth2 |
5
|
|
|
* |
6
|
|
|
* Platine OAuth2 is a library that implements the OAuth2 specification |
7
|
|
|
* |
8
|
|
|
* This content is released under the MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2020 Platine OAuth2 |
11
|
|
|
* |
12
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
13
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
14
|
|
|
* in the Software without restriction, including without limitation the rights |
15
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
16
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
17
|
|
|
* furnished to do so, subject to the following conditions: |
18
|
|
|
* |
19
|
|
|
* The above copyright notice and this permission notice shall be included in all |
20
|
|
|
* copies or substantial portions of the Software. |
21
|
|
|
* |
22
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
23
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
24
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
25
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
26
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
27
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
28
|
|
|
* SOFTWARE. |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
declare(strict_types=1); |
32
|
|
|
|
33
|
|
|
namespace Platine\OAuth2\Entity; |
34
|
|
|
|
35
|
|
|
use Stringable; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @class Scope |
39
|
|
|
* @package Platine\OAuth2\Entity |
40
|
|
|
*/ |
41
|
|
|
class Scope implements Stringable |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* The scope id |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
protected int $id; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The scope name |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected string $name; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The scope description |
57
|
|
|
* @var string|null |
58
|
|
|
*/ |
59
|
|
|
protected ?string $description = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Whether is the default scope |
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
protected bool $isDefault = false; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Can not rewrite the constructor in child classes |
69
|
|
|
*/ |
70
|
|
|
final public function __construct() |
71
|
|
|
{ |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Create new scope |
76
|
|
|
* @param int $id |
77
|
|
|
* @param string $name |
78
|
|
|
* @param string|null $description |
79
|
|
|
* @param bool $isDefault |
80
|
|
|
* @return self |
81
|
|
|
*/ |
82
|
|
|
public static function createNewScope( |
83
|
|
|
int $id, |
84
|
|
|
string $name, |
85
|
|
|
?string $description = null, |
86
|
|
|
bool $isDefault = false |
87
|
|
|
): self { |
88
|
|
|
$scope = new static(); |
89
|
|
|
$scope->id = $id; |
90
|
|
|
$scope->name = $name; |
91
|
|
|
$scope->description = $description; |
92
|
|
|
$scope->isDefault = $isDefault; |
93
|
|
|
|
94
|
|
|
return $scope; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Create scope using given data |
99
|
|
|
* @param array<string, mixed> $data |
100
|
|
|
* @return self |
101
|
|
|
*/ |
102
|
|
|
public static function hydrate(array $data): self |
103
|
|
|
{ |
104
|
|
|
$scope = new static(); |
105
|
|
|
$scope->id = $data['id']; |
106
|
|
|
$scope->name = $data['name']; |
107
|
|
|
$scope->description = $data['description']; |
108
|
|
|
$scope->isDefault = $data['is_default']; |
109
|
|
|
|
110
|
|
|
return $scope; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Return the id |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
|
|
public function getId(): int |
118
|
|
|
{ |
119
|
|
|
return $this->id; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Return the name |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getName(): string |
127
|
|
|
{ |
128
|
|
|
return $this->name; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Return the description |
133
|
|
|
* @return string|null |
134
|
|
|
*/ |
135
|
|
|
public function getDescription(): ?string |
136
|
|
|
{ |
137
|
|
|
return $this->description; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Whether is the default scope |
142
|
|
|
* @return bool |
143
|
|
|
*/ |
144
|
|
|
public function isDefault(): bool |
145
|
|
|
{ |
146
|
|
|
return $this->isDefault; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
|
|
public function __toString(): string |
155
|
|
|
{ |
156
|
|
|
return $this->name; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|