|
| 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 | +use function method_exists; |
| 16 | + |
| 17 | +#[AsCommand( |
| 18 | + 'event-sourcing:schema:subscription-teardown', |
| 19 | + 'teardown subscription (pub/sub) for store', |
| 20 | +)] |
| 21 | +final class SchemaSubscriptionTeardownCommand extends Command |
| 22 | +{ |
| 23 | + public function __construct( |
| 24 | + private readonly Store $store, |
| 25 | + ) { |
| 26 | + parent::__construct(); |
| 27 | + } |
| 28 | + |
| 29 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 30 | + { |
| 31 | + $io = new OutputStyle($input, $output); |
| 32 | + |
| 33 | + if (!$this->store instanceof SubscriptionStore) { |
| 34 | + $io->error('store does not support subscriptions'); |
| 35 | + |
| 36 | + return 1; |
| 37 | + } |
| 38 | + |
| 39 | + if (!$this->store->supportSubscription()) { |
| 40 | + $io->error('store does not support subscriptions'); |
| 41 | + |
| 42 | + return 1; |
| 43 | + } |
| 44 | + |
| 45 | + if (method_exists($this->store, 'teardownSubscription')) { |
| 46 | + $this->store->teardownSubscription(); |
| 47 | + |
| 48 | + return 0; |
| 49 | + } |
| 50 | + |
| 51 | + $io->error('store does not support teardownSubscription'); |
| 52 | + |
| 53 | + return 1; |
| 54 | + } |
| 55 | +} |
0 commit comments