13
13
14
14
namespace phpDocumentor \Guides \Cli \Command ;
15
15
16
+ use Doctrine \Deprecations \Deprecation ;
16
17
use Flyfinder \Path ;
17
18
use Flyfinder \Specification \InPath ;
18
19
use Flyfinder \Specification \NotSpecification ;
25
26
use phpDocumentor \FileSystem \FlySystemAdapter ;
26
27
use phpDocumentor \Guides \Cli \Logger \SpyProcessor ;
27
28
use phpDocumentor \Guides \Compiler \CompilerContext ;
28
- use phpDocumentor \Guides \Event \PostCollectFilesForParsingEvent ;
29
- use phpDocumentor \Guides \Event \PostParseDocument ;
30
- use phpDocumentor \Guides \Event \PostParseProcess ;
31
29
use phpDocumentor \Guides \Event \PostProjectNodeCreated ;
32
- use phpDocumentor \Guides \Event \PostRenderDocument ;
33
- use phpDocumentor \Guides \Event \PostRenderProcess ;
34
- use phpDocumentor \Guides \Event \PreParseDocument ;
35
- use phpDocumentor \Guides \Event \PreRenderDocument ;
36
- use phpDocumentor \Guides \Event \PreRenderProcess ;
37
30
use phpDocumentor \Guides \Handlers \CompileDocumentsCommand ;
38
31
use phpDocumentor \Guides \Handlers \ParseDirectoryCommand ;
39
32
use phpDocumentor \Guides \Handlers \ParseFileCommand ;
46
39
use Psr \Log \LogLevel ;
47
40
use RuntimeException ;
48
41
use Symfony \Component \Console \Command \Command ;
49
- use Symfony \Component \Console \Helper \ProgressBar ;
50
42
use Symfony \Component \Console \Input \InputArgument ;
51
43
use Symfony \Component \Console \Input \InputInterface ;
52
44
use Symfony \Component \Console \Input \InputOption ;
63
55
use function implode ;
64
56
use function is_countable ;
65
57
use function is_dir ;
66
- use function microtime ;
67
58
use function pathinfo ;
68
59
use function sprintf ;
69
60
use function strtoupper ;
@@ -77,6 +68,7 @@ public function __construct(
77
68
private readonly SettingsManager $ settingsManager ,
78
69
private readonly ClockInterface $ clock ,
79
70
private readonly EventDispatcher $ eventDispatcher ,
71
+ private readonly ProgressBarSubscriber $ progressBarSubscriber ,
80
72
) {
81
73
parent ::__construct ('run ' );
82
74
@@ -156,76 +148,12 @@ public function __construct(
156
148
157
149
public function registerProgressBar (ConsoleOutputInterface $ output ): void
158
150
{
159
- $ parsingProgressBar = new ProgressBar ($ output ->section ());
160
- $ parsingProgressBar ->setFormat ('Parsing: %current%/%max% [%bar%] %percent:3s%% %message% ' );
161
- $ parsingStartTime = microtime (true );
162
- $ this ->eventDispatcher ->addListener (
163
- PostCollectFilesForParsingEvent::class,
164
- static function (PostCollectFilesForParsingEvent $ event ) use ($ parsingProgressBar , &$ parsingStartTime ): void {
165
- // Each File needs to be first parsed then rendered
166
- $ parsingStartTime = microtime (true );
167
- $ parsingProgressBar ->setMaxSteps (count ($ event ->getFiles ()));
168
- },
169
- );
170
- $ this ->eventDispatcher ->addListener (
171
- PreParseDocument::class,
172
- static function (PreParseDocument $ event ) use ($ parsingProgressBar ): void {
173
- $ parsingProgressBar ->setMessage ('Parsing file: ' . $ event ->getFileName ());
174
- $ parsingProgressBar ->display ();
175
- },
176
- );
177
- $ this ->eventDispatcher ->addListener (
178
- PostParseDocument::class,
179
- static function (PostParseDocument $ event ) use ($ parsingProgressBar ): void {
180
- $ parsingProgressBar ->advance ();
181
- },
182
- );
183
- $ this ->eventDispatcher ->addListener (
184
- PostParseProcess::class,
185
- static function (PostParseProcess $ event ) use ($ parsingProgressBar , $ parsingStartTime ): void {
186
- $ parsingTimeElapsed = microtime (true ) - $ parsingStartTime ;
187
- $ parsingProgressBar ->setMessage (sprintf (
188
- 'Parsed %s files in %.2f seconds ' ,
189
- $ parsingProgressBar ->getMaxSteps (),
190
- $ parsingTimeElapsed ,
191
- ));
192
- $ parsingProgressBar ->finish ();
193
- },
194
- );
195
- $ that = $ this ;
196
- $ this ->eventDispatcher ->addListener (
197
- PreRenderProcess::class,
198
- static function (PreRenderProcess $ event ) use ($ that , $ output ): void {
199
- $ renderingProgressBar = new ProgressBar ($ output ->section (), count ($ event ->getCommand ()->getDocumentArray ()));
200
- $ renderingProgressBar ->setFormat ('Rendering: %current%/%max% [%bar%] %percent:3s%% Output format ' . $ event ->getCommand ()->getOutputFormat () . ': %message% ' );
201
- $ renderingStartTime = microtime (true );
202
- $ that ->eventDispatcher ->addListener (
203
- PreRenderDocument::class,
204
- static function (PreRenderDocument $ event ) use ($ renderingProgressBar ): void {
205
- $ renderingProgressBar ->setMessage ('Rendering: ' . $ event ->getCommand ()->getFileDestination ());
206
- $ renderingProgressBar ->display ();
207
- },
208
- );
209
- $ that ->eventDispatcher ->addListener (
210
- PostRenderDocument::class,
211
- static function (PostRenderDocument $ event ) use ($ renderingProgressBar ): void {
212
- $ renderingProgressBar ->advance ();
213
- },
214
- );
215
- $ that ->eventDispatcher ->addListener (
216
- PostRenderProcess::class,
217
- static function (PostRenderProcess $ event ) use ($ renderingProgressBar , $ renderingStartTime ): void {
218
- $ renderingElapsedTime = microtime (true ) - $ renderingStartTime ;
219
- $ renderingProgressBar ->setMessage (sprintf (
220
- 'Rendered %s documents in %.2f seconds ' ,
221
- $ renderingProgressBar ->getMaxSteps (),
222
- $ renderingElapsedTime ,
223
- ));
224
- $ renderingProgressBar ->finish ();
225
- },
226
- );
227
- },
151
+ Deprecation::trigger (
152
+ 'phpdocumentor/guides-cli ' ,
153
+ 'https://github.com/phpdocumentor/guides/issues/33 ' ,
154
+ 'Progressbar will be registered via settings ' ,
228
155
);
156
+ $ this ->progressBarSubscriber ->subscribe ($ output , $ this ->eventDispatcher );
229
157
}
230
158
231
159
private function getSettingsOverriddenWithInput (InputInterface $ input ): ProjectSettings
@@ -323,7 +251,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
323
251
324
252
325
253
if ($ output instanceof ConsoleOutputInterface && $ settings ->isShowProgressBar ()) {
326
- $ this ->registerProgressBar ($ output );
254
+ $ this ->progressBarSubscriber -> subscribe ($ output, $ this -> eventDispatcher );
327
255
}
328
256
329
257
if ($ settings ->getInputFile () === '' ) {
0 commit comments