1 | <?php |
||
18 | class ProvidingProgressBar |
||
19 | { |
||
20 | const PROGRESS_BAR_TEMPLATE = ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'; |
||
21 | |||
22 | /** |
||
23 | * @var OutputInterface |
||
24 | */ |
||
25 | private $output; |
||
26 | |||
27 | /** |
||
28 | * @var ProgressBar |
||
29 | * |
||
30 | * public for test purpose |
||
31 | */ |
||
32 | public $progressBar; |
||
33 | |||
34 | /** |
||
35 | * @param EventDispatcherInterface $dispatcher |
||
36 | * @param OutputInterface $output |
||
37 | */ |
||
38 | 6 | public function __construct( |
|
39 | EventDispatcherInterface $dispatcher, |
||
40 | OutputInterface $output |
||
41 | ) { |
||
42 | 6 | $this->output = $output; |
|
43 | |||
44 | 6 | $dispatcher->addListener( |
|
45 | 6 | 'elasticsearch.has_started_handling', |
|
46 | 6 | [$this, 'onStartedHandling'] |
|
47 | 6 | ); |
|
48 | |||
49 | 6 | $dispatcher->addListener( |
|
50 | 6 | 'elasticsearch.has_started_providing', |
|
51 | 6 | [$this, 'onStartedProviding'] |
|
52 | 6 | ); |
|
53 | |||
54 | 6 | $dispatcher->addListener( |
|
55 | 6 | 'elasticsearch.has_provided_document', |
|
56 | 6 | [$this, 'onProvidedDocument'] |
|
57 | 6 | ); |
|
58 | |||
59 | 6 | $dispatcher->addListener( |
|
60 | 6 | 'elasticsearch.has_finished_providing', |
|
61 | 6 | [$this, 'onFinishedProviding'] |
|
62 | 6 | ); |
|
63 | 6 | } |
|
64 | |||
65 | 1 | public function onStartedHandling(HasStartedHandling $event) |
|
74 | |||
75 | 2 | public function onStartedProviding(HasStartedProviding $event) |
|
90 | |||
91 | 1 | public function onProvidedDocument(HasProvidedDocument $event) |
|
92 | { |
||
93 | 1 | if ($this->progressBar) { |
|
94 | 1 | $this->progressBar->advance(); |
|
95 | 1 | } |
|
96 | 1 | } |
|
97 | |||
98 | 1 | public function onFinishedProviding(HasFinishedProviding $event) |
|
104 | } |
||
105 |