Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace DrupalCodeGenerator\Helper;
|
Chris@0
|
4
|
Chris@0
|
5 use Symfony\Component\Console\Helper\Helper;
|
Chris@0
|
6 use Symfony\Component\Console\Output\OutputInterface;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Output printer for generators.
|
Chris@0
|
10 */
|
Chris@0
|
11 class OutputHandler extends Helper {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * {@inheritdoc}
|
Chris@0
|
15 */
|
Chris@0
|
16 public function getName() {
|
Chris@0
|
17 return 'dcg_output_handler';
|
Chris@0
|
18 }
|
Chris@0
|
19
|
Chris@0
|
20 /**
|
Chris@0
|
21 * Prints summary.
|
Chris@0
|
22 *
|
Chris@0
|
23 * @param \Symfony\Component\Console\Output\OutputInterface $output
|
Chris@0
|
24 * Output instance.
|
Chris@0
|
25 * @param array $dumped_files
|
Chris@0
|
26 * List of created or updated files.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function printSummary(OutputInterface $output, array $dumped_files) {
|
Chris@0
|
29
|
Chris@0
|
30 if (count($dumped_files) > 0) {
|
Chris@0
|
31 // Multiple hooks can be dumped to the same file.
|
Chris@0
|
32 $dumped_files = array_unique($dumped_files);
|
Chris@0
|
33
|
Chris@0
|
34 usort($dumped_files, function ($a, $b) {
|
Chris@0
|
35 $depth_a = substr_count($a, '/');
|
Chris@0
|
36 $depth_b = substr_count($b, '/');
|
Chris@0
|
37 // Top level files should be printed first.
|
Chris@0
|
38 return $depth_a == $depth_b || ($depth_a > 1 && $depth_b > 1) ?
|
Chris@0
|
39 strcmp($a, $b) : ($depth_a > $depth_b ? 1 : -1);
|
Chris@0
|
40 });
|
Chris@0
|
41
|
Chris@0
|
42 $output->writeln('');
|
Chris@0
|
43 $output->writeln(' The following directories and files have been created or updated:');
|
Chris@0
|
44 $output->writeln('<fg=cyan;options=bold>–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––</>');
|
Chris@0
|
45 foreach ($dumped_files as $file) {
|
Chris@0
|
46 $output->writeln(" • $file");
|
Chris@0
|
47 }
|
Chris@0
|
48 $output->writeln('');
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 }
|