Repository navigation
Expand file tree
/
Copy pathmodule.php
More file actions
52 lines (48 loc) · 2.34 KB
/
Copy pathmodule.php
File metadata and controls
52 lines (48 loc) · 2.34 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
<?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\Sending\DnsHostResolver;
use Marko\Webhook\Sending\WebhookDispatcher;
use Marko\Webhook\Sending\WebhookUrlPolicy;
return [
'bindings' => [
WebhookDispatcherInterface::class => WebhookDispatcher::class,
WebhookUrlPolicyInterface::class => WebhookUrlPolicy::class,
HostResolverInterface::class => DnsHostResolver::class,
WebhookReceiverInterface::class => WebhookReceiver::class,
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));
},
],
'arguments' => [
WebhookReceiver::class => [
// The replay guard is only resolved when webhook.replay_protection is on, so marko/cache stays optional.
'replayGuard' => fn (ContainerInterface $container): ?WebhookReplayGuardInterface => $container->get(
WebhookConfig::class,
)->replayProtection
? $container->get(WebhookReplayGuardInterface::class)
: null,
],
],
'globalMiddleware' => [
WebhookEndpointMiddleware::class,
],
];