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
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core;
|
|
|
|
use Core\Events\WebhookRegistering;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
/**
|
|
* Core service provider shim for boot-time webhook type registration.
|
|
*
|
|
* Stores the collected webhook type registry in the container after the
|
|
* application has fully booted so downstream services can resolve it.
|
|
*/
|
|
class CoreServiceProvider extends ServiceProvider
|
|
{
|
|
public const WEBHOOK_TYPES = 'core.webhook.types';
|
|
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(self::WEBHOOK_TYPES, static fn (): array => []);
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
$this->app->booted(function (): void {
|
|
$this->app->instance(self::WEBHOOK_TYPES, static::fireWebhookRegistering());
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Fire WebhookRegistering and return the collected type registry.
|
|
*
|
|
* @return array<string, array<string, mixed>>
|
|
*/
|
|
public static function fireWebhookRegistering(): array
|
|
{
|
|
$event = new WebhookRegistering;
|
|
event($event);
|
|
|
|
return $event->types();
|
|
}
|
|
|
|
/**
|
|
* Get the webhook type registry captured during boot.
|
|
*
|
|
* @return array<string, array<string, mixed>>
|
|
*/
|
|
public static function webhookTypes(): array
|
|
{
|
|
return app()->bound(self::WEBHOOK_TYPES)
|
|
? app(self::WEBHOOK_TYPES)
|
|
: [];
|
|
}
|
|
}
|