|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2017 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command; |
|
20
|
|
|
|
|
21
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
22
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
23
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
24
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
25
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
26
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
27
|
|
|
|
|
28
|
|
|
class ReplaySpecificEventsCommand extends ContainerAwareCommand |
|
29
|
|
|
{ |
|
30
|
|
|
const OPTION_LIST_EVENTS = 'list-events'; |
|
31
|
|
|
|
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
$this |
|
35
|
|
|
->setName('stepup:event:replay') |
|
36
|
|
|
->setDescription('replay specified events for specified projectors') |
|
37
|
|
|
->addOption( |
|
38
|
|
|
self::OPTION_LIST_EVENTS, |
|
39
|
|
|
null, |
|
40
|
|
|
InputOption::VALUE_NONE, |
|
41
|
|
|
'List all events available to replay' |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
46
|
|
|
{ |
|
47
|
|
|
$container = $this->getContainer(); |
|
48
|
|
|
$eventCollection = $container->get('middleware.event_replay.event_collection'); |
|
49
|
|
|
|
|
50
|
|
|
if ($input->getOption(self::OPTION_LIST_EVENTS)) { |
|
51
|
|
|
$output->writeln('<info>The following events can be replayed:</info>'); |
|
52
|
|
|
$output->writeln(iterator_to_array($eventCollection)); |
|
53
|
|
|
|
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** @var QuestionHelper $questionHelper */ |
|
58
|
|
|
$questionHelper = $this->getHelper('question'); |
|
59
|
|
|
|
|
60
|
|
|
$selectEventsQuestion = new ChoiceQuestion( |
|
61
|
|
|
'Which events would you like to replay? Please supply a comma-separated list of numbers.', |
|
62
|
|
|
iterator_to_array($eventCollection) |
|
63
|
|
|
); |
|
64
|
|
|
$selectEventsQuestion->setMultiselect(true); |
|
65
|
|
|
|
|
66
|
|
|
$chosenEvents = $questionHelper->ask($input, $output, $selectEventsQuestion); |
|
67
|
|
|
$eventCollection->select($chosenEvents); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|