1 | <?php |
||
15 | class ConsoleProgressWriter implements Writer |
||
16 | { |
||
17 | /** |
||
18 | * @var OutputInterface |
||
19 | */ |
||
20 | protected $output; |
||
21 | |||
22 | /** |
||
23 | * @var ProgressBar |
||
24 | */ |
||
25 | protected $progress; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $verbosity; |
||
31 | |||
32 | /** |
||
33 | * @var CountableReader |
||
34 | */ |
||
35 | protected $reader; |
||
36 | |||
37 | /** |
||
38 | * @var integer |
||
39 | */ |
||
40 | protected $redrawFrequency; |
||
41 | |||
42 | /** |
||
43 | * @param OutputInterface $output |
||
44 | * @param CountableReader $reader |
||
45 | * @param string $verbosity |
||
46 | * @param integer $redrawFrequency |
||
47 | */ |
||
48 | 1 | public function __construct( |
|
49 | OutputInterface $output, |
||
50 | CountableReader $reader, |
||
51 | $verbosity = 'debug', |
||
52 | $redrawFrequency = 1 |
||
53 | ) { |
||
54 | 1 | $this->output = $output; |
|
55 | 1 | $this->reader = $reader; |
|
56 | 1 | $this->verbosity = $verbosity; |
|
57 | 1 | $this->redrawFrequency = $redrawFrequency; |
|
58 | 1 | } |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 1 | public function prepare() |
|
64 | { |
||
65 | 1 | $this->progress = new ProgressBar($this->output, $this->reader->count()); |
|
66 | 1 | $this->progress->setFormat($this->verbosity); |
|
67 | 1 | $this->progress->setRedrawFrequency($this->redrawFrequency); |
|
68 | 1 | $this->progress->start(); |
|
69 | 1 | } |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 1 | public function writeItem(array $item) |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 1 | public function finish() |
|
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | 1 | public function getVerbosity() |
|
91 | { |
||
92 | 1 | return $this->verbosity; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return integer |
||
97 | */ |
||
98 | public function getRedrawFrequency() |
||
102 | } |
||
103 |