-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink.php
100 lines (81 loc) · 1.99 KB
/
Link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace OAuth2Framework\Component\WebFingerEndpoint;
class Link implements \JsonSerializable
{
private string $rel;
private ?string $type;
private ?string $href;
private array $titles;
private array $properties;
/**
* @param string[] $titles
* @param mixed[] $properties
*/
public function __construct(string $rel, ?string $type, ?string $href, array $titles, array $properties)
{
$this->rel = $rel;
$this->type = $type;
$this->href = $href;
$this->titles = $titles;
$this->properties = $properties;
}
public function getRel(): string
{
return $this->rel;
}
public function getType(): ?string
{
return $this->type;
}
public function getHref(): ?string
{
return $this->href;
}
/**
* @return string[]
*/
public function getTitles(): array
{
return $this->titles;
}
public function addTitle(string $tag, string $title): void
{
$this->titles[$tag] = $title;
}
/**
* @return string[]
*/
public function getProperties(): array
{
return $this->properties;
}
public function addProperty(string $key, string $property): void
{
$this->properties[$key] = $property;
}
public function jsonSerialize(): array
{
$result = [
'rel' => $this->rel,
'type' => $this->type,
'href' => $this->href,
'titles' => $this->titles,
'properties' => $this->properties,
];
foreach ($result as $k => $v) {
if (null === $v || (\is_array($v) && 0 === \count($v))) {
unset($result[$k]);
}
}
return $result;
}
}