You've already forked php-auth
generated from siteworxpro/Php-Template
Initial commit
This commit is contained in:
30
src/CommandBus/Handlers/ExampleHandler.php
Normal file
30
src/CommandBus/Handlers/ExampleHandler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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 . '!';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user