Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 23
CRAP
0.00% covered (danger)
0.00%
0 / 1
cli_iohandler
0.00% covered (danger)
0.00%
0 / 73
0.00% covered (danger)
0.00%
0 / 23
1482
0.00% covered (danger)
0.00%
0 / 1
 set_style
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 get_input
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 get_raw_input
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_input
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_server_variable
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_header_variable
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_secure
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_user_form_group
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 send_response
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_error_message
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 add_warning_message
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 add_log_message
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 add_success_message
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 set_task_count
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
 set_progress
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 finish_progress
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 request_refresh
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_active_stage_menu
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_finished_stage_menu
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 set_cookie
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 add_download_link
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 render_update_file_status
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 redirect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\install\helper\iohandler;
15
16use phpbb\install\exception\installer_exception;
17use Symfony\Component\Console\Output\OutputInterface;
18use Symfony\Component\Console\Style\OutputStyle;
19
20/**
21 * Input-Output handler for the CLI frontend
22 */
23class cli_iohandler extends iohandler_base
24{
25    /**
26     * @var OutputInterface
27     */
28    protected $output;
29
30    /**
31     * @var OutputStyle
32     */
33    protected $io;
34
35    /**
36     * @var array
37     */
38    protected $input_values = array();
39
40    /**
41     * @var \Symfony\Component\Console\Helper\ProgressBar|null
42     */
43    protected $progress_bar;
44
45    /**
46     * Set the style and output used to display feedback;
47     *
48     * @param OutputStyle         $style
49     * @param OutputInterface    $output
50     */
51    public function set_style(OutputStyle $style, OutputInterface $output)
52    {
53        $this->io = $style;
54        $this->output = $output;
55    }
56
57    /**
58     * {@inheritdoc}
59     */
60    public function get_input($name, $default, $multibyte = false)
61    {
62        $result = $default;
63
64        if (isset($this->input_values[$name]))
65        {
66            $result = $this->input_values[$name];
67        }
68
69        if ($multibyte)
70        {
71            return utf8_normalize_nfc($result);
72        }
73
74        return $result;
75    }
76
77    /**
78     * {@inheritdoc}
79     */
80    public function get_raw_input($name, $default)
81    {
82        return $this->get_input($name, $default, true);
83    }
84
85    /**
86     * Set input variable
87     *
88     * @param string $name Name of input variable
89     * @param mixed $value Value of input variable
90     */
91    public function set_input($name, $value)
92    {
93        $this->input_values[$name] = $value;
94    }
95
96    /**
97     * {@inheritdoc}
98     */
99    public function get_server_variable($name, $default = '')
100    {
101        return $default;
102    }
103
104    /**
105     * {@inheritdoc}
106     */
107    public function get_header_variable($name, $default = '')
108    {
109        return $default;
110    }
111
112    /**
113     * {@inheritdoc}
114     */
115    public function is_secure()
116    {
117        return false;
118    }
119
120    /**
121     * {@inheritdoc}
122     */
123    public function add_user_form_group($title, $form)
124    {
125        throw new installer_exception('MISSING_DATA');
126    }
127
128    /**
129     * {@inheritdoc}
130     */
131    public function send_response($no_more_output = false)
132    {
133    }
134
135    /**
136     * {@inheritdoc
137     */
138    public function add_error_message($error_title, $error_description = false)
139    {
140        $this->io->newLine();
141        $message = $this->translate_message($error_title, $error_description);
142        $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
143
144        if (strpos($message_string, '<br />') !== false)
145        {
146            $message_string = strip_tags(str_replace('<br />', "\n", $message_string));
147        }
148
149        $this->io->error($message_string);
150
151        if ($this->progress_bar !== null)
152        {
153            $this->io->newLine(2);
154            $this->progress_bar->display();
155        }
156    }
157
158    /**
159     * {@inheritdoc
160     */
161    public function add_warning_message($warning_title, $warning_description = false)
162    {
163        $this->io->newLine();
164
165        $message = $this->translate_message($warning_title, $warning_description);
166        $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
167        $this->io->warning($message_string);
168
169        if ($this->progress_bar !== null)
170        {
171            $this->io->newLine(2);
172            $this->progress_bar->display();
173        }
174    }
175
176    /**
177     * {@inheritdoc
178     */
179    public function add_log_message($log_title, $log_description = false)
180    {
181        if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL)
182        {
183            $message = $this->translate_message($log_title, $log_description);
184            $this->output->writeln(sprintf('[%3d/%-3d] ---- %s', $this->current_task_progress, $this->task_progress_count, $message['title']));
185        }
186    }
187
188    /**
189     * {@inheritdoc
190     */
191    public function add_success_message($success_title, $success_description = false)
192    {
193        $this->io->newLine();
194
195        $message = $this->translate_message($success_title, $success_description);
196        $message_string = $message['title'] . (!empty($message['description']) ? "\n" . $message['description'] : '');
197        $this->io->success($message_string);
198
199        if ($this->progress_bar !== null)
200        {
201            $this->io->newLine(2);
202            $this->progress_bar->display();
203        }
204    }
205
206    /**
207     * {@inheritdoc}
208     */
209    public function set_task_count($task_count, $restart = false)
210    {
211        parent::set_task_count($task_count, $restart);
212
213        if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL)
214        {
215            if ($this->progress_bar !== null)
216            {
217                // Symfony's ProgressBar is immutable regarding task_count, so delete the old and create a new one.
218                $this->progress_bar->clear();
219            }
220            else
221            {
222                $this->io->newLine(2);
223            }
224
225            $this->progress_bar = $this->io->createProgressBar($task_count);
226            $this->progress_bar->setFormat(
227                "    %current:3s%/%max:-3s% %bar%  %percent:3s%%\n" .
228                "             %message%\n");
229            $this->progress_bar->setBarWidth(60);
230
231            if (!defined('PHP_WINDOWS_VERSION_BUILD'))
232            {
233                $this->progress_bar->setEmptyBarCharacter('░'); // light shade character \u2591
234                $this->progress_bar->setProgressCharacter('');
235                $this->progress_bar->setBarCharacter('▓'); // dark shade character \u2593
236            }
237
238            $this->progress_bar->setMessage('');
239            $this->progress_bar->start();
240        }
241    }
242
243    /**
244     * {@inheritdoc}
245     */
246    public function set_progress($task_lang_key, $task_number)
247    {
248        parent::set_progress($task_lang_key, $task_number);
249
250        if ($this->progress_bar !== null)
251        {
252            $this->progress_bar->setProgress($this->current_task_progress);
253            $this->progress_bar->setMessage($this->current_task_name);
254        }
255        else
256        {
257            $this->output->writeln(sprintf('[%3d/%-3d] %s', $this->current_task_progress, $this->task_progress_count, $this->current_task_name));
258        }
259    }
260
261    /**
262     * {@inheritdoc}
263     */
264    public function finish_progress($message_lang_key)
265    {
266        parent::finish_progress($message_lang_key);
267
268        if ($this->progress_bar !== null)
269        {
270            $this->progress_bar->finish();
271            $this->progress_bar = null;
272        }
273    }
274
275    /**
276     * {@inheritdoc}
277     */
278    public function request_refresh()
279    {
280    }
281
282    /**
283     * {@inheritdoc}
284     */
285    public function set_active_stage_menu($menu_path)
286    {
287    }
288
289    /**
290     * {@inheritdoc}
291     */
292    public function set_finished_stage_menu($menu_path)
293    {
294    }
295
296    /**
297     * {@inheritdoc}
298     */
299    public function set_cookie($cookie_name, $cookie_value)
300    {
301    }
302
303    /**
304     * {@inheritdoc}
305     */
306    public function add_download_link($route, $title, $msg = null)
307    {
308    }
309
310    /**
311     * {@inheritdoc}
312     */
313    public function render_update_file_status($status_array)
314    {
315    }
316
317    /**
318     * {@inheritdoc}
319     */
320    public function redirect($url, $use_ajax = false)
321    {
322    }
323}