You've already forked php-auth
generated from siteworxpro/Php-Template
31 lines
839 B
PHP
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 . '!';
|
|
}
|
|
}
|