|
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\WebFingerEndpoint; |
|
15
|
|
|
|
|
16
|
|
|
class ResourceDescriptor implements \JsonSerializable |
|
17
|
|
|
{ |
|
18
|
|
|
private $subject; |
|
19
|
|
|
private $aliases; |
|
20
|
|
|
private $properties; |
|
21
|
|
|
private $links; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param string[] $aliases |
|
25
|
|
|
* @param mixed[] $properties |
|
26
|
|
|
* @param Link[] $links |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(?string $subject, array $aliases, array $properties, array $links) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->subject = $subject; |
|
31
|
|
|
$this->aliases = $aliases; |
|
32
|
|
|
$this->properties = $properties; |
|
33
|
|
|
$this->links = $links; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getSubject(): ?string |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
return $this->subject; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return string[] |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getAliases(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->aliases; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function addAlias(string $key, string $alias): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->properties[$key] = $alias; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return mixed[] |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getProperties(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->properties; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function addProperty(string $key, string $property): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->properties[$key] = $property; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Link[] |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getLinks(): array |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->links; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function addLink(string $key, Link $link): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->links[$key] = $link; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function jsonSerialize() |
|
81
|
|
|
{ |
|
82
|
|
|
$result = []; |
|
83
|
|
|
|
|
84
|
|
|
foreach (['subject', 'aliases', 'properties', 'links'] as $property) { |
|
85
|
|
|
if (!empty($this->$property)) { |
|
86
|
|
|
$result[$property] = $this->$property; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $result; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
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
@returnannotation as described here.