Skip to content

Commit 19d23a6

Browse files
committed
add subscription setup cli commands & skip setup in subscription run
1 parent fe23cbc commit 19d23a6

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcing\Console\Command;
6+
7+
use Patchlevel\EventSourcing\Console\OutputStyle;
8+
use Patchlevel\EventSourcing\Store\Store;
9+
use Patchlevel\EventSourcing\Store\SubscriptionStore;
10+
use Symfony\Component\Console\Attribute\AsCommand;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
#[AsCommand(
16+
'event-sourcing:schema:subscription-setup',
17+
'setup subscription (pub/sub) for store',
18+
)]
19+
final class SchemaSubscriptionSetupCommand extends Command
20+
{
21+
public function __construct(
22+
private readonly Store $store,
23+
) {
24+
parent::__construct();
25+
}
26+
27+
protected function execute(InputInterface $input, OutputInterface $output): int
28+
{
29+
$io = new OutputStyle($input, $output);
30+
31+
if (!$this->store instanceof SubscriptionStore) {
32+
$io->error('store does not support subscriptions');
33+
34+
return 1;
35+
}
36+
37+
if (!$this->store->supportSubscription()) {
38+
$io->error('store does not support subscriptions');
39+
40+
return 1;
41+
}
42+
43+
$this->store->setupSubscription();
44+
45+
return 0;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcing\Console\Command;
6+
7+
use Patchlevel\EventSourcing\Console\OutputStyle;
8+
use Patchlevel\EventSourcing\Store\Store;
9+
use Patchlevel\EventSourcing\Store\SubscriptionStore;
10+
use Symfony\Component\Console\Attribute\AsCommand;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
#[AsCommand(
16+
'event-sourcing:schema:subscription-setup',
17+
'setup subscription (pub/sub) for store',
18+
)]
19+
final class SchemaSubscriptionSetupCommand extends Command
20+
{
21+
public function __construct(
22+
private readonly Store $store,
23+
) {
24+
parent::__construct();
25+
}
26+
27+
protected function execute(InputInterface $input, OutputInterface $output): int
28+
{
29+
$io = new OutputStyle($input, $output);
30+
31+
if (!$this->store instanceof SubscriptionStore) {
32+
$io->error('store does not support subscriptions');
33+
34+
return 1;
35+
}
36+
37+
if (!$this->store->supportSubscription()) {
38+
$io->error('store does not support subscriptions');
39+
40+
return 1;
41+
}
42+
43+
$this->store->setupSubscription();
44+
45+
return 0;
46+
}
47+
}

0 commit comments

Comments
 (0)