Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console-core / src / Utils / ShowFile.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Core\Command\ShowFileHelper.
6  */
7
8 namespace Drupal\Console\Core\Utils;
9
10 use Drupal\Console\Core\Style\DrupalStyle;
11
12 /**
13  * Class ShowFileHelper
14  *
15  * @package Drupal\Console\Core\Utils
16  */
17 class ShowFile
18 {
19     /**
20      * @var string
21      */
22     protected $root;
23
24     /**
25      * @var TranslatorManagerInterface
26      */
27     protected $translator;
28
29     /**
30      * ShowFile constructor.
31      *
32      * @param string                     $root
33      * @param TranslatorManagerInterface $translator
34      */
35     public function __construct(
36         $root,
37         TranslatorManagerInterface $translator
38     ) {
39         $this->root = $root;
40         $this->translator = $translator;
41     }
42
43     /**
44      * @param DrupalStyle $io
45      * @param string      $files
46      * @param boolean     $showPath
47      */
48     public function generatedFiles($io, $files, $showPath = true)
49     {
50         $pathKey = null;
51         $path = null;
52         if ($showPath) {
53             $pathKey = 'application.user.messages.path';
54             $path = $this->root;
55         }
56         $this->showMMultiple(
57             $io,
58             $files,
59             'application.messages.files.generated',
60             $pathKey,
61             $path
62         );
63     }
64
65     /**
66      * @param DrupalStyle $io
67      * @param string      $files
68      * @param boolean     $showPath
69      */
70     public function copiedFiles($io, $files, $showPath = true)
71     {
72         $pathKey = null;
73         $path = null;
74         if ($showPath) {
75             $pathKey = 'application.user.messages.path';
76             $path = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '/\\').'/.console/';
77         }
78         $this->showMMultiple(
79             $io,
80             $files,
81             'application.messages.files.copied',
82             $pathKey,
83             $path
84         );
85     }
86
87     /**
88      * @param DrupalStyle $io
89      * @param array       $files
90      * @param string      $headerKey
91      * @param string      $pathKey
92      * @param string      $path
93      */
94     private function showMMultiple($io, $files, $headerKey, $pathKey, $path)
95     {
96         if (!$files) {
97             return;
98         }
99
100         $io->writeln($this->translator->trans($headerKey));
101
102         if ($pathKey) {
103             $io->info(
104                 sprintf('%s:', $this->translator->trans($pathKey)),
105                 false
106             );
107         }
108         if ($path) {
109             $io->comment($path, false);
110         }
111         $io->newLine();
112
113         $index = 1;
114         foreach ($files as $file) {
115             $this->showSingle($io, $file, $index);
116             ++$index;
117         }
118     }
119
120     /**
121      * @param DrupalStyle $io
122      * @param string      $file
123      * @param int         $index
124      */
125     private function showSingle(DrupalStyle $io, $file, $index)
126     {
127         $io->info(
128             sprintf('%s -', $index),
129             false
130         );
131         $io->comment($file, false);
132         $io->newLine();
133     }
134 }