-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from skoro/4-external-services-notifications
Subscribers and notifications
- Loading branch information
Showing
53 changed files
with
1,972 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
when@test: | ||
dama_doctrine_test: | ||
enable_static_connection: true | ||
enable_static_meta_data_cache: true | ||
enable_static_query_cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240901095458 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE subscribers ( | ||
id INT AUTO_INCREMENT NOT NULL, | ||
uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\', | ||
hash VARCHAR(255) NOT NULL, | ||
channel_type VARCHAR(255) NOT NULL, | ||
order_status VARCHAR(255) NOT NULL, | ||
channel_message VARCHAR(255) NOT NULL, | ||
params JSON NOT NULL, | ||
created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', | ||
UNIQUE INDEX UNIQ_2FCD16ACD17F50A6 (uuid), | ||
UNIQUE INDEX UNIQ_2FCD16ACD1B862B8 (hash), | ||
INDEX IDX_2FCD16ACB88F75C9 (order_status), | ||
PRIMARY KEY(id) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP TABLE subscribers'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Command; | ||
|
||
use App\Entity\OrderStatus; | ||
use App\Subscriber\Action\AddHttpSubscriberAction; | ||
use App\Subscriber\Channel\HttpNotificationChannel; | ||
use Exception; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand( | ||
name: 'subscriber:add-http', | ||
description: 'Add a subscriber of HTTP channel notification', | ||
)] | ||
final class SubscriberAddHttpCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly AddHttpSubscriberAction $addHttpSubscriberAction, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->addArgument('url', InputArgument::REQUIRED, 'Url to call.') | ||
->addOption( | ||
'http-method', | ||
'X', | ||
InputOption::VALUE_OPTIONAL, | ||
'Http request method', | ||
HttpNotificationChannel::DEFAULT_HTTP_METHOD, | ||
) | ||
->addOption( | ||
'order-status', | ||
's', | ||
InputOption::VALUE_REQUIRED, | ||
'Expected order status: ' . OrderStatus::formattedString(), | ||
'' | ||
) | ||
->addOption( | ||
'channel-message', | ||
'm', | ||
InputOption::VALUE_REQUIRED, | ||
'Channel message type (see output of "subscriber:channels" for available message types)', | ||
'' | ||
) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$url = $input->getArgument('url'); | ||
$httpMethod = $input->getOption('http-method'); | ||
$orderStatusValue = $input->getOption('order-status'); | ||
$channelMessage = $input->getOption('channel-message'); | ||
|
||
try { | ||
if (! ($orderStatus = OrderStatus::tryFrom($orderStatusValue))) { | ||
throw new Exception( | ||
sprintf('Invalid order status: "%s". Expected: %s.', | ||
$orderStatusValue, | ||
OrderStatus::formattedString() | ||
) | ||
); | ||
} | ||
|
||
$subscriber = $this->addHttpSubscriberAction->add($orderStatus, $url, $channelMessage, $httpMethod); | ||
|
||
$io->success("Subscriber \"{$subscriber->getUuid()}\" has been added."); | ||
} catch (\Throwable $e) { | ||
$io->error($e->getMessage()); | ||
return Command::FAILURE; | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Command; | ||
|
||
use App\Subscriber\Channel\NotificationChannelCollection; | ||
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:channels', | ||
description: 'Show a list of registered subscriber notification channels and messages', | ||
)] | ||
final class SubscriberChannelsCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly NotificationChannelCollection $channelCollection, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$channelTypes = $this->channelCollection->getNotificationChannelTypes(); | ||
$messageTypes = $this->channelCollection->getMessageTypes(); | ||
|
||
if ($channelTypes) { | ||
$io->title('Notification channels:'); | ||
$io->block($channelTypes); | ||
} else { | ||
$io->warning('No subscriber notification channels found.'); | ||
} | ||
|
||
if ($messageTypes) { | ||
$io->title('Channel messages:'); | ||
$io->block($messageTypes); | ||
} else { | ||
$io->warning('No channel messages found.'); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.