1313
1414namespace phpDocumentor \Guides \Cli \Command ;
1515
16+ use Doctrine \Deprecations \Deprecation ;
1617use Flyfinder \Path ;
1718use Flyfinder \Specification \InPath ;
1819use Flyfinder \Specification \NotSpecification ;
2526use phpDocumentor \FileSystem \FlySystemAdapter ;
2627use phpDocumentor \Guides \Cli \Logger \SpyProcessor ;
2728use phpDocumentor \Guides \Compiler \CompilerContext ;
28- use phpDocumentor \Guides \Event \PostCollectFilesForParsingEvent ;
29- use phpDocumentor \Guides \Event \PostParseDocument ;
30- use phpDocumentor \Guides \Event \PostParseProcess ;
3129use 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 ;
3730use phpDocumentor \Guides \Handlers \CompileDocumentsCommand ;
3831use phpDocumentor \Guides \Handlers \ParseDirectoryCommand ;
3932use phpDocumentor \Guides \Handlers \ParseFileCommand ;
4639use Psr \Log \LogLevel ;
4740use RuntimeException ;
4841use Symfony \Component \Console \Command \Command ;
49- use Symfony \Component \Console \Helper \ProgressBar ;
5042use Symfony \Component \Console \Input \InputArgument ;
5143use Symfony \Component \Console \Input \InputInterface ;
5244use Symfony \Component \Console \Input \InputOption ;
6355use function implode ;
6456use function is_countable ;
6557use function is_dir ;
66- use function microtime ;
6758use function pathinfo ;
6859use function sprintf ;
6960use function strtoupper ;
@@ -77,6 +68,7 @@ public function __construct(
7768 private readonly SettingsManager $ settingsManager ,
7869 private readonly ClockInterface $ clock ,
7970 private readonly EventDispatcher $ eventDispatcher ,
71+ private readonly ProgressBarSubscriber $ progressBarSubscriber ,
8072 ) {
8173 parent ::__construct ('run ' );
8274
@@ -156,76 +148,12 @@ public function __construct(
156148
157149 public function registerProgressBar (ConsoleOutputInterface $ output ): void
158150 {
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 ' ,
228155 );
156+ $ this ->progressBarSubscriber ->subscribe ($ output , $ this ->eventDispatcher );
229157 }
230158
231159 private function getSettingsOverriddenWithInput (InputInterface $ input ): ProjectSettings
@@ -323,7 +251,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
323251
324252
325253 if ($ output instanceof ConsoleOutputInterface && $ settings ->isShowProgressBar ()) {
326- $ this ->registerProgressBar ($ output );
254+ $ this ->progressBarSubscriber -> subscribe ($ output, $ this -> eventDispatcher );
327255 }
328256
329257 if ($ settings ->getInputFile () === '' ) {
0 commit comments