blob: 4445cad2571a31bab76dfb0048defa199148915c (
plain)
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
|
<?php
use WpfTest\GlobalConfig;
use WpfTest\HttpResponseStatus\BadRequest;
use WpfTest\HttpResponseStatus\NotFound;
use WpfTest\Router;
Router::getInstance()->mount('/.well-known/webfinger', function (array $args) {
if (!isset($_GET['resource'])) {
throw new BadRequest('parameter `resource` is required');
}
$resource = $_GET['resource'];
if (!str_starts_with($resource, 'acct:')) {
throw new BadRequest('only acct: URIs are supported');
}
$handle = substr($resource, 5);
[$localPart, $remotePart] = explode('@', $handle, 2);
if ($remotePart != GlobalConfig::getInstance()->getCanonicalHost()) {
throw new NotFound('i only know about local accounts');
}
if ($localPart != 'winter') {
throw new NotFound('i only know about winter!!!');
}
json_response([
'subject' => "acct:$localPart@$remotePart",
'links' => [
[
'rel' => 'urn:example:wpf:actor',
'href' => path_to_uri('/user/winter'),
'type' => 'application/json'
]
]
]);
});
|