comparison vendor/chi-teck/drupal-code-generator/src/Helper/OutputHandler.php @ 0:c75dbcec494b

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