1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author Julius Härtl <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OC\Accounts; |
28
|
|
|
|
29
|
|
|
use OCP\Accounts\IAccountManager; |
30
|
|
|
use OCP\Accounts\IAccountProperty; |
31
|
|
|
|
32
|
|
|
class AccountProperty implements IAccountProperty { |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $name; |
36
|
|
|
/** @var string */ |
37
|
|
|
private $value; |
38
|
|
|
/** @var string */ |
39
|
|
|
private $scope; |
40
|
|
|
/** @var string */ |
41
|
|
|
private $verified; |
42
|
|
|
|
43
|
|
|
public function __construct(string $name, string $value, string $scope, string $verified) { |
44
|
|
|
$this->name = $name; |
45
|
|
|
$this->value = $value; |
46
|
|
|
$this->scope = $this->mapScopeToV2($scope); |
47
|
|
|
$this->verified = $verified; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function jsonSerialize() { |
51
|
|
|
return [ |
52
|
|
|
'name' => $this->getName(), |
53
|
|
|
'value' => $this->getValue(), |
54
|
|
|
'scope' => $this->getScope(), |
55
|
|
|
'verified' => $this->getVerified() |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Set the value of a property |
61
|
|
|
* |
62
|
|
|
* @since 15.0.0 |
63
|
|
|
* |
64
|
|
|
* @param string $value |
65
|
|
|
* @return IAccountProperty |
66
|
|
|
*/ |
67
|
|
|
public function setValue(string $value): IAccountProperty { |
68
|
|
|
$this->value = $value; |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set the scope of a property |
74
|
|
|
* |
75
|
|
|
* @since 15.0.0 |
76
|
|
|
* |
77
|
|
|
* @param string $scope |
78
|
|
|
* @return IAccountProperty |
79
|
|
|
*/ |
80
|
|
|
public function setScope(string $scope): IAccountProperty { |
81
|
|
|
$this->scope = $this->mapScopeToV2($scope); |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Set the verification status of a property |
87
|
|
|
* |
88
|
|
|
* @since 15.0.0 |
89
|
|
|
* |
90
|
|
|
* @param string $verified |
91
|
|
|
* @return IAccountProperty |
92
|
|
|
*/ |
93
|
|
|
public function setVerified(string $verified): IAccountProperty { |
94
|
|
|
$this->verified = $verified; |
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get the name of a property |
100
|
|
|
* |
101
|
|
|
* @since 15.0.0 |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getName(): string { |
106
|
|
|
return $this->name; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the value of a property |
111
|
|
|
* |
112
|
|
|
* @since 15.0.0 |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getValue(): string { |
117
|
|
|
return $this->value; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get the scope of a property |
122
|
|
|
* |
123
|
|
|
* @since 15.0.0 |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getScope(): string { |
128
|
|
|
return $this->scope; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public static function mapScopeToV2($scope) { |
132
|
|
|
if (strpos($scope, 'v2-') === 0) { |
133
|
|
|
return $scope; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
switch ($scope) { |
137
|
|
|
case IAccountManager::VISIBILITY_PRIVATE: |
|
|
|
|
138
|
|
|
return IAccountManager::SCOPE_LOCAL; |
139
|
|
|
case IAccountManager::VISIBILITY_CONTACTS_ONLY: |
|
|
|
|
140
|
|
|
return IAccountManager::SCOPE_FEDERATED; |
141
|
|
|
case IAccountManager::VISIBILITY_PUBLIC: |
|
|
|
|
142
|
|
|
return IAccountManager::SCOPE_PUBLISHED; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return IAccountManager::SCOPE_LOCAL; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get the verification status of a property |
150
|
|
|
* |
151
|
|
|
* @since 15.0.0 |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function getVerified(): string { |
156
|
|
|
return $this->verified; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.