Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #276 from f500/update-console-commands-to-symfony5…
Browse files Browse the repository at this point in the history
…-standards

Update console commands to symfony5 standards
  • Loading branch information
ramondelafuente authored Dec 4, 2019
2 parents 032ac5b + 96f3774 commit c68f810
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
2 changes: 2 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,7 @@ services:

Tooling\SymfonyConsole\:
resource: '../src/Tooling/SymfonyConsole/'
arguments:
$eventStore: '@prooph_event_store.herd_store'
tags:
- 'console.command'
34 changes: 24 additions & 10 deletions src/Tooling/SymfonyConsole/CreateEventStreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,50 @@
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Stream;
use Prooph\EventStore\StreamName;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class CreateEventStreamCommand extends ContainerAwareCommand
final class CreateEventStreamCommand extends Command
{
/**
* @var EventStore
*/
private $eventStore;

/**
* @var string
*/
protected static $defaultName = 'event-store:event-stream:create';

protected function configure(): void
{
$this->setName('event-store:event-stream:create')
->setDescription('Create event_stream.')
$this->setDescription('Create event_stream.')
->setHelp('This command creates the event_stream');
}

public function __construct(EventStore $eventStore)
{
parent::__construct();

$this->eventStore = $eventStore;
}

/**
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var EventStore $eventStore */
$eventStore = $this->getContainer()->get('prooph_event_store.herd_store');

$streamName = new StreamName('event_stream');

if ($eventStore->hasStream($streamName)) {
if ($this->eventStore->hasStream($streamName)) {
return 0;
}

$eventStore->create(new Stream($streamName, new ArrayIterator([])));
$this->eventStore->create(new Stream($streamName, new ArrayIterator([])));
$output->writeln('<info>Event stream was created successfully.</info>');

return 0;
Expand Down
24 changes: 17 additions & 7 deletions src/Tooling/SymfonyConsole/DeleteEventStreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,27 @@
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Exception\StreamNotFound;
use Prooph\EventStore\StreamName;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

final class DeleteEventStreamCommand extends ContainerAwareCommand
final class DeleteEventStreamCommand extends Command
{
protected function configure(): void
/**
* @var EventStore
*/
private $eventStore;

/**
* @var string
*/
protected static $defaultName = 'event-store:event-stream:delete';

public function __construct(EventStore $eventStore)
{
$this->setName('event-store:event-stream:delete');
parent::__construct();
$this->eventStore = $eventStore;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -32,14 +43,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

try {
/** @var EventStore $eventStore */
$eventStore = $this->getContainer()->get('prooph_event_store.herd_store');
$eventStore->delete(new StreamName('event_stream'));
$this->eventStore->delete(new StreamName('event_stream'));
} catch (StreamNotFound $exception) {
// Fine by us.
}

$output->writeln('<info>Event stream was deleted successfully.</info>');

return 0;
}
}

0 comments on commit c68f810

Please sign in to comment.