-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWellKnownConfig.php
89 lines (75 loc) · 2.07 KB
/
WellKnownConfig.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
<?php
declare(strict_types=1);
namespace Revolution\Bluesky\WellKnown;
use Closure;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Revolution\Bluesky\Support\DID;
class WellKnownConfig
{
protected static ?Closure $didUsing = null;
protected static ?Closure $atprotoDidUsing = null;
/**
* Overrides the `/.well-known/did.json` response.
*
* ```
* // AppServiceProvider::boot()
*
* WellKnownConfig::didUsing(function () {
* return [];
* });
* ```
*/
public static function didUsing(?callable $callback): void
{
static::$didUsing = is_callable($callback) ? $callback(...) : null;
}
/**
* Default is a setting for FeedGenerator.
*/
public static function did(): mixed
{
if (is_callable(static::$didUsing)) {
return call_user_func(static::$didUsing);
}
$endpoint = Str::rtrim(url('/'), '/');
$service = [];
if (! Config::boolean('bluesky.generator.disabled')) {
$service[] = [
'id' => '#bsky_fg',
'type' => 'BskyFeedGenerator',
'serviceEndpoint' => $endpoint,
];
}
return [
'@context' => [
'https://www.w3.org/ns/did/v1',
],
'id' => config('bluesky.generator.service') ?? DID::web(),
'service' => $service,
];
}
/**
* Overrides the `/.well-known/atproto-did` response.
*
* ```
* // AppServiceProvider::boot()
*
* WellKnownConfig::atprotoDidUsing(fn() => 'did:plc:***');
* ```
*/
public static function atprotoDidUsing(?callable $callback): void
{
static::$atprotoDidUsing = is_callable($callback) ? $callback(...) : null;
}
/**
* Default is empty, since it can also be set by DNS.
*/
public static function atprotoDid(): mixed
{
if (is_callable(static::$atprotoDidUsing)) {
return call_user_func(static::$atprotoDidUsing);
}
return '';
}
}