Skip to content

Commit

Permalink
#4 console command to get registered subscriber notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
skoro committed Aug 31, 2024
1 parent 0c5f8a3 commit b632277
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Command/SubscriberNotificationsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Command;

use App\Subscriber\Notification\NotificationHandlerCollection;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'subscriber:notifications',
description: 'Show a list of registered subscriber notification types',
)]
final class SubscriberNotificationsCommand extends Command
{
public function __construct(
private readonly NotificationHandlerCollection $handlerCollection,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$handlerTypes = $this->handlerCollection->getHandlerTypes();

if ($handlerTypes) {
$io->title('Notification handlers:');
$io->block($handlerTypes);
} else {
$io->warning('No subscriber notification handlers found.');
}

return Command::SUCCESS;
}
}

0 comments on commit b632277

Please sign in to comment.