Repository navigation
Expand file tree
/
Copy pathmodule.php
More file actions
57 lines (52 loc) · 2.6 KB
/
Copy pathmodule.php
File metadata and controls
57 lines (52 loc) · 2.6 KB
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
<?php
declare(strict_types=1);
use Marko\Cache\Contracts\CacheInterface;
use Marko\Config\Exceptions\ConfigException;
use Marko\Core\Container\ContainerInterface;
use Marko\Webhook\Config\WebhookConfig;
use Marko\Webhook\Contracts\HostResolverInterface;
use Marko\Webhook\Contracts\WebhookDispatcherInterface;
use Marko\Webhook\Contracts\WebhookReceiverInterface;
use Marko\Webhook\Contracts\WebhookReplayGuardInterface;
use Marko\Webhook\Contracts\WebhookUrlPolicyInterface;
use Marko\Webhook\Middleware\WebhookEndpointMiddleware;
use Marko\Webhook\Receiving\CacheReplayGuard;
use Marko\Webhook\Receiving\WebhookReceiver;
use Marko\Webhook\Receiving\WebhookVerifier;
use Marko\Webhook\Sending\DnsHostResolver;
use Marko\Webhook\Sending\WebhookDispatcher;
use Marko\Webhook\Sending\WebhookUrlPolicy;
use Psr\Clock\ClockInterface;
return [
'bindings' => [
WebhookDispatcherInterface::class => WebhookDispatcher::class,
WebhookUrlPolicyInterface::class => WebhookUrlPolicy::class,
HostResolverInterface::class => DnsHostResolver::class,
WebhookReceiverInterface::class => WebhookReceiver::class,
// The replay guard is only resolved when webhook.replay_protection is on, so marko/cache stays optional.
WebhookReceiver::class => function (ContainerInterface $container): WebhookReceiver {
$config = $container->get(WebhookConfig::class);
return new WebhookReceiver(
verifier: $container->get(WebhookVerifier::class),
webhookConfig: $config,
clock: $container->get(ClockInterface::class),
replayGuard: $config->replayProtection
? $container->get(WebhookReplayGuardInterface::class)
: null,
);
},
WebhookReplayGuardInterface::class => function (ContainerInterface $container): WebhookReplayGuardInterface {
if (!interface_exists(CacheInterface::class)) {
throw new ConfigException(
message: 'Configuration key "webhook.replay_protection" is true, but marko/cache is not installed',
context: 'While resolving the replay guard that remembers received X-Webhook-Id values.',
suggestion: 'Run composer require marko/cache plus a shared cache driver (e.g. marko/cache-redis), bind your own WebhookReplayGuardInterface, or set webhook.replay_protection to false.',
);
}
return new CacheReplayGuard($container->get(CacheInterface::class));
},
],
'globalMiddleware' => [
WebhookEndpointMiddleware::class,
],
];