PHP code example of rasuvaeff / yii3-outbox-webhooks-bridge
1. Go to this page and download the library: Download rasuvaeff/yii3-outbox-webhooks-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rasuvaeff / yii3-outbox-webhooks-bridge example snippets
use Rasuvaeff\Yii3OutboxWebhooksBridge\ConfigWebhookEndpointProvider;
use Rasuvaeff\Yii3Webhooks\WebhookEndpoint;
$endpointProvider = new ConfigWebhookEndpointProvider(map: [
'order.created' => [
new WebhookEndpoint(url: 'https://partner-a.example.com/hooks', secret: 'secret-a'),
new WebhookEndpoint(url: 'https://partner-b.example.com/hooks', secret: 'secret-b'),
],
'order.paid' => [
new WebhookEndpoint(url: 'https://partner-a.example.com/hooks', secret: 'secret-a'),
],
]);
use Rasuvaeff\Yii3OutboxWebhooksBridge\OutboxWebhookPublisher;
$publisher = new OutboxWebhookPublisher(
dispatcher: $dispatcher, // your WebhookDispatcher impl
endpointProvider: $endpointProvider,
deliveryStorage: $deliveryStorage, // e.g. DbWebhookDeliveryStorage
);
use Rasuvaeff\Yii3Outbox\Processor;
use Rasuvaeff\Yii3Outbox\RetryPolicy;
$processor = new Processor(
storage: $outboxStorage,
publisher: $publisher,
retryPolicy: new RetryPolicy(maxAttempts: 5, delaySeconds: 60),
clock: $clock,
types: $endpointProvider->configuredTypes(), // only what has endpoints
);
// In a background worker or console command:
$result = $processor->process();
final readonly class OwnedTypesPublisher implements PublisherInterface
{
/** @param list<string> $types */
public function __construct(
private PublisherInterface $inner,
private array $types,
) {}
public function publish(OutboxMessage $message): void
{
if (!in_array($message->getType(), $this->types, true)) {
throw new PublishException(
message: sprintf('Message type "%s" is not owned by the webhook publisher', $message->getType()),
outboxMessage: $message,
);
}
$this->inner->publish($message);
}
}
use Rasuvaeff\Yii3OutboxWebhooksBridge\WebhookEndpointProvider;
use Rasuvaeff\Yii3Webhooks\WebhookEndpoint;
final readonly class DbWebhookEndpointProvider implements WebhookEndpointProvider
{
public function __construct(private \PDO $db) {}
public function getEndpointsForType(string $type): array
{
// load from DB...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.