NovinkaZverejnili sme 50+ Laravel balíkov ako open source
Custom AI apps, agents and automation — Roundly ConsultingRoundly
Všetky balíky

Fasáda je odporúčaná predvoľba, nie jediná cesta. RoundlyConsulting\Webhooks\WebhooksManager je koreň fasády — scoped väzba, ktorú môžete injektovať — a každé volanie fasády končí v jednej akcii. Všetky tri štýly spúšťajú rovnaký kód:

// Send an event
Webhooks::send($endpoint, 'invoice.paid', ['invoice' => 42]);
$webhooks->send($endpoint, 'invoice.paid', ['invoice' => 42]);                       // WebhooksManager $webhooks, injected
app(SendWebhookAction::class)->execute($endpoint, 'invoice.paid', ['invoice' => 42]);

// Create an inbound endpoint
$created = Webhooks::inbound()->create(handler: 'billing');
$created = $webhooks->inbound()->create(handler: 'billing');
$created = app(CreateInboundEndpointAction::class)->execute(null, 'billing');

// Run the inbound pipeline (what the route does)
$response = Webhooks::inbound()->receive($key, $request);
$response = $webhooks->inbound()->receive($key, $request);
$response = app(ReceiveWebhookAction::class)->execute($key, $request);

// Redeliver
Webhooks::outbound()->redeliver($delivery);
$webhooks->outbound()->redeliver($delivery);
app(RedeliverWebhookAction::class)->execute($delivery);

Injektovanie manažéra

use RoundlyConsulting\Webhooks\Models\OutboundDelivery;
use RoundlyConsulting\Webhooks\Models\OutboundEndpoint;
use RoundlyConsulting\Webhooks\WebhooksManager;

final readonly class InvoiceWebhooks
{
    public function __construct(private WebhooksManager $webhooks) {}

    public function paid(OutboundEndpoint $endpoint, int $invoice): OutboundDelivery
    {
        return $this->webhooks->send($endpoint, 'invoice.paid', ['invoice' => $invoice], id: "invoice-{$invoice}-paid");
    }
}

Fake rozširuje manažér, takže pri Webhooks::fake() je fake aj injektovaný WebhooksManager. Ostatné verejné metódy manažéra (createInboundEndpoint(), rotateOutboundSecret(), redeliverFailed() a ďalšie) sú interné — volajú ich prístupy, aby fake videl každé volanie. Používajte prístupy.

Volanie akcie

use RoundlyConsulting\Webhooks\Actions\Inbound\CreateInboundEndpointAction;
use RoundlyConsulting\Webhooks\Actions\Outbound\SendWebhookAction;

app(SendWebhookAction::class)->execute($endpoint, 'invoice.paid', ['invoice' => 42]);
app(CreateInboundEndpointAction::class)->execute($team, 'billing');   // the owner comes first

Každá akcia určená aplikácii je final readonly, vytvára sa z kontajnera a má jednu metódu execute(). Akcie obchádzajú fake aj obmedzenie na vlastníka — pracujú s tým, čo im odovzdáte — preto ich používajte na skladanie vlastných prípadov použitia a inde fasádu alebo manažér.

Metóda fasády → akcia

Menné priestory sú relatívne k RoundlyConsulting\Webhooks\Actions:

Metóda fasádyAkciaexecute()
inbound()->create()Inbound\CreateInboundEndpointAction?Model $owner = null, ?string $handler = null, string $scheme = 'default', ?string $name = null, ?string $secret = null, ?InboundEndpointOptions $options = null
inbound()->update()Inbound\UpdateInboundEndpointActionInboundEndpoint $endpoint, InboundEndpointChanges $changes
inbound()->enable() · disable()Inbound\SetInboundEndpointStateActionInboundEndpoint $endpoint, bool $enabled
inbound()->delete()Inbound\DeleteInboundEndpointActionInboundEndpoint $endpoint
inbound()->rotateSecret()Inbound\RotateInboundSecretActionInboundEndpoint $endpoint, ?CarbonInterface $grace = null, ?string $secret = null
inbound()->receive()Inbound\ReceiveWebhookActionstring $key, Request $request
inbound()->verify()Inbound\VerifyInboundRequestActionInboundEndpoint $endpoint, Request $request, ?string $body = null, bool $deferCommit = false
inbound()->replay()Inbound\ReplayInboundDeliveryActionInboundDelivery $delivery
outbound()->create()Outbound\CreateOutboundEndpointActionstring $url, array $events = ['*'], ?string $name = null, array $headers = [], string $scheme = 'default', ?OutboundEndpointOptions $options = null, ?Model $owner = null
outbound()->update()Outbound\UpdateOutboundEndpointActionOutboundEndpoint $endpoint, OutboundEndpointChanges $changes
outbound()->enable() · disable()Outbound\SetOutboundEndpointStateActionOutboundEndpoint $endpoint, bool $enabled
outbound()->delete()Outbound\DeleteOutboundEndpointActionOutboundEndpoint $endpoint
outbound()->rotateSecret()Outbound\RotateOutboundSecretActionOutboundEndpoint $endpoint, ?CarbonInterface $grace = null
send()Outbound\SendWebhookActionOutboundEndpoint $endpoint, string $eventType, array|Arrayable|JsonSerializable $payload, ?string $id = null
broadcast() · for($owner)->broadcast()Outbound\BroadcastWebhookActionstring $eventType, array|Arrayable|JsonSerializable $payload, ?Model $owner = null
outbound()->ping()Outbound\PingEndpointActionOutboundEndpoint $endpoint
outbound()->redeliver()Outbound\RedeliverWebhookActionOutboundDelivery $delivery
outbound()->redeliverFailed()Outbound\RedeliverFailedDeliveriesActionOutboundEndpoint $endpoint, ?CarbonInterface $since = null, bool $includeCancelled = false
outbound()->dispatchDue()Outbound\DispatchDueDeliveriesAction—
prune()PruneAction?PruneOptions $options = null

Dve poznámky: CreateInboundEndpointAction berie vlastníka ako prvý argument a VerifyInboundRequestAction prijíma aj už prečítané surové telo a $deferCommit — pri true dostanete closure commit z verdiktu, ktorý spustíte pred ďalšou akciou. AcceptInboundDeliveryAction, ProcessInboundDeliveryAction, AttemptDeliveryAction, ScheduleRetryAction, RecordEndpointFailureAction, DisableOutboundEndpointAction a CancelPendingDeliveriesAction sú interné stavebné bloky.

Prejavte lásku k open source

Tento balík je zadarmo pod licenciou MIT. Ak vám šetrí čas, jednorazový príspevok alebo členstvo na Patreone nám pomôže ho ďalej udržiavať, testovať a dokumentovať.

Ďalšie spôsoby podpory vrátane kryptomien

Odoslaním daru súhlasíte s našimi podmienkami prijímania darov.

Chcete to zabudovať do svojho produktu?

Naše balíky integrujeme do zákazkových Laravel a AI riešení. Napíšte nám, na čom pracujete, a ozveme sa do 48 hodín.