feat: implement custom event dispatcher and listener system (#13)
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m38s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m38s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 1m40s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 1m52s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 1m51s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m21s

Reviewed-on: #13
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #13.
This commit is contained in:
2025-11-11 16:12:19 +00:00
committed by Siteworx Pro Gitea
parent 7d0b00fb89
commit eeb46bc982
8 changed files with 325 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Siteworxpro\App\Services\Facades;
use Siteworxpro\App\Events\Dispatcher as DispatcherConcrete;
use Siteworxpro\App\Services\Facade;
/**
* Class Dispatcher
*
* A facade for the event dispatcher.
*
* @package Siteworxpro\App\Services\Facades
*
* @method static void listen(string $event, callable|string $listener)
* @method static void dispatch(object|string $event, array $payload = [], bool $halt = false)
* @method static void push(object|string $event, array $payload = [])
* @method static array|null until(object|string $event, array $payload = [])
* @method static bool hasListeners(string $eventName)
* @method static void subscribe(mixed $subscriber)
*/
class Dispatcher extends Facade
{
/**
* Get the registered name of the component.
*
* @return string The name of the component.
*/
protected static function getFacadeAccessor(): string
{
return DispatcherConcrete::class;
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Siteworxpro\App\Services\ServiceProviders;
use Illuminate\Support\ServiceProvider;
use Siteworxpro\App\Events\Dispatcher;
class DispatcherServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Dispatcher::class, function () {
return new Dispatcher();
});
}
}