WebhookRegistering event exposes: - register(string $type, array $spec): add a webhook type to the registry - types(): array — queryable post-dispatch registry CoreServiceProvider dispatches the event at app boot and exposes the collected registry via webhookTypes() — matches the existing ApiRoutesRegistering / ConsoleBooting / ClientRoutesRegistering event-driven module pattern. Pairs with #1034 ofm.bot WebhookRegistrar (just landed) — that service can now also be wired through this event, allowing OTHER modules and external apps using Core to register webhook types via the standard Core lifecycle. Note: real Core lifecycle dispatcher lives in a sibling read-only framework checkout. CoreServiceProvider here is a local shim that mirrors the dispatch behaviour. Upstream patch needed when that sibling lands. Pest covers: instantiation + register, boot-time dispatch, post-boot registry lookup. Co-authored-by: Codex <noreply@openai.com> Closes tasks.lthn.sh/view.php?id=1013
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Events;
|
|
|
|
/**
|
|
* Fired when webhook ingress types are being registered.
|
|
*
|
|
* Modules and external applications listen to this event to publish the
|
|
* webhook types they want Core to expose during application boot.
|
|
*
|
|
* ## When This Event Fires
|
|
*
|
|
* Fired once the application has booted and webhook ingress definitions are
|
|
* being collected for the active runtime.
|
|
*
|
|
* ## Usage Example
|
|
*
|
|
* ```php
|
|
* public static array $listens = [
|
|
* WebhookRegistering::class => 'onWebhookRegistering',
|
|
* ];
|
|
*
|
|
* public function onWebhookRegistering(WebhookRegistering $event): void
|
|
* {
|
|
* $event->register('myapp.event.x', [
|
|
* 'payload' => [
|
|
* 'id' => 'string',
|
|
* ],
|
|
* ]);
|
|
* }
|
|
* ```
|
|
*/
|
|
class WebhookRegistering extends LifecycleEvent
|
|
{
|
|
/** @var array<string, array<string, mixed>> Collected webhook type definitions keyed by type */
|
|
protected array $types = [];
|
|
|
|
/**
|
|
* Register a webhook type definition.
|
|
*
|
|
* Later registrations with the same type replace earlier definitions so an
|
|
* application can override defaults during boot.
|
|
*
|
|
* @param string $type Fully qualified webhook type name
|
|
* @param array<string, mixed> $definition Payload shape or metadata for the type
|
|
*/
|
|
public function register(string $type, array $definition = []): void
|
|
{
|
|
$this->types[$type] = $definition;
|
|
}
|
|
|
|
/**
|
|
* Get all registered webhook type definitions.
|
|
*
|
|
* @return array<string, array<string, mixed>>
|
|
*
|
|
* @internal Used by the webhook ingress bootstrap
|
|
*/
|
|
public function types(): array
|
|
{
|
|
return $this->types;
|
|
}
|
|
}
|