Files
Php-Template/src/CommandBus/Handlers/ExampleHandler.php
Ron Rise aa4526dd5a
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m52s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m12s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 3m16s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 3m7s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 3m11s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m28s
feat: implement command bus with attribute-based handler resolution and add example command and handler
2025-12-21 15:56:53 -05:00

31 lines
839 B
PHP

<?php
declare(strict_types=1);
namespace Siteworxpro\App\CommandBus\Handlers;
use Siteworxpro\App\Attributes\CommandBus\HandlesCommand;
use Siteworxpro\App\CommandBus\Commands\Command;
use Siteworxpro\App\CommandBus\Commands\ExampleCommand;
use Siteworxpro\App\Services\Facades\Logger;
#[HandlesCommand(ExampleCommand::class)]
class ExampleHandler extends CommandHandler
{
/**
* @param Command|ExampleCommand $command
* @return string
*/
public function __invoke(Command|ExampleCommand $command): string
{
if (!method_exists($command, 'getName')) {
throw new \TypeError('Invalid command type provided to ExampleHandler.');
}
$name = $command->getName();
Logger::info('Handling ExampleCommand for name: ' . $name);
return 'Hello, ' . $name . '!';
}
}