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

Commit c68f810

Browse files
Merge pull request #276 from f500/update-console-commands-to-symfony5-standards
Update console commands to symfony5 standards
2 parents 032ac5b + 96f3774 commit c68f810

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

config/services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,7 @@ services:
134134

135135
Tooling\SymfonyConsole\:
136136
resource: '../src/Tooling/SymfonyConsole/'
137+
arguments:
138+
$eventStore: '@prooph_event_store.herd_store'
137139
tags:
138140
- 'console.command'

src/Tooling/SymfonyConsole/CreateEventStreamCommand.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,50 @@
88
use Prooph\EventStore\EventStore;
99
use Prooph\EventStore\Stream;
1010
use Prooph\EventStore\StreamName;
11-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
11+
use Symfony\Component\Console\Command\Command;
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
1414

15-
final class CreateEventStreamCommand extends ContainerAwareCommand
15+
final class CreateEventStreamCommand extends Command
1616
{
17+
/**
18+
* @var EventStore
19+
*/
20+
private $eventStore;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected static $defaultName = 'event-store:event-stream:create';
26+
1727
protected function configure(): void
1828
{
19-
$this->setName('event-store:event-stream:create')
20-
->setDescription('Create event_stream.')
29+
$this->setDescription('Create event_stream.')
2130
->setHelp('This command creates the event_stream');
2231
}
2332

33+
public function __construct(EventStore $eventStore)
34+
{
35+
parent::__construct();
36+
37+
$this->eventStore = $eventStore;
38+
}
39+
2440
/**
25-
* @param InputInterface $input
41+
* @param InputInterface $input
2642
* @param OutputInterface $output
43+
* @return int
2744
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
2845
*/
2946
protected function execute(InputInterface $input, OutputInterface $output): int
3047
{
31-
/** @var EventStore $eventStore */
32-
$eventStore = $this->getContainer()->get('prooph_event_store.herd_store');
33-
3448
$streamName = new StreamName('event_stream');
3549

36-
if ($eventStore->hasStream($streamName)) {
50+
if ($this->eventStore->hasStream($streamName)) {
3751
return 0;
3852
}
3953

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

4357
return 0;

src/Tooling/SymfonyConsole/DeleteEventStreamCommand.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@
77
use Prooph\EventStore\EventStore;
88
use Prooph\EventStore\Exception\StreamNotFound;
99
use Prooph\EventStore\StreamName;
10-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10+
use Symfony\Component\Console\Command\Command;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Console\Question\ConfirmationQuestion;
1414

15-
final class DeleteEventStreamCommand extends ContainerAwareCommand
15+
final class DeleteEventStreamCommand extends Command
1616
{
17-
protected function configure(): void
17+
/**
18+
* @var EventStore
19+
*/
20+
private $eventStore;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected static $defaultName = 'event-store:event-stream:delete';
26+
27+
public function __construct(EventStore $eventStore)
1828
{
19-
$this->setName('event-store:event-stream:delete');
29+
parent::__construct();
30+
$this->eventStore = $eventStore;
2031
}
2132

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

3445
try {
35-
/** @var EventStore $eventStore */
36-
$eventStore = $this->getContainer()->get('prooph_event_store.herd_store');
37-
$eventStore->delete(new StreamName('event_stream'));
46+
$this->eventStore->delete(new StreamName('event_stream'));
3847
} catch (StreamNotFound $exception) {
3948
// Fine by us.
4049
}
4150

4251
$output->writeln('<info>Event stream was deleted successfully.</info>');
52+
4353
return 0;
4454
}
4555
}

0 commit comments

Comments
 (0)