ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IOWrapper.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\CLI;
22
24use Symfony\Component\Console\Input\InputInterface;
25use Symfony\Component\Console\Output\OutputInterface;
26use Symfony\Component\Console\Style\SymfonyStyle;
27
33{
34 public const LABEL_WIDTH = 75;
35 public const ELLIPSIS = "...";
36
37 protected InputInterface $in;
38 protected OutputInterface $out;
39 protected SymfonyStyle $style;
40 protected bool $last_objective_was_notable = false;
41 protected string $last_objective_label = "";
42 protected bool $output_in_objective = false;
43
44 public function __construct(InputInterface $in, OutputInterface $out)
45 {
46 $this->in = $in;
47 $this->out = $out;
48 $this->style = new SymfonyStyle($in, $out);
49 }
50
51 // Implementation of AdminInteraction
52 public function startProgress(int $max): void
53 {
54 $this->style->progressStart($max);
55 }
56
57 public function advanceProgress(): void
58 {
59 $this->style->progressAdvance();
60 }
61
62 public function stopProgress(): void
63 {
64 $this->style->progressFinish();
65 }
66
67 public function inform(string $message): void
68 {
69 $this->outputInObjective();
70 $this->style->note($message);
71 }
72
73 public function confirmExplicit(string $message, string $type_text_to_confirm): bool
74 {
75 $this->outputInObjective();
76 if (!$this->shouldSayYes()) {
77 return $this->style->ask(
79 null,
80 fn (string $input): bool => $type_text_to_confirm === $input
81 );
82 } else {
83 $this->inform("Automatically confirmed:\n\n$message");
84 return true;
85 }
86 }
87
88 public function confirmOrDeny(string $message): bool
89 {
90 $this->outputInObjective();
91 if (!$this->shouldSayYes()) {
92 return $this->style->confirm($message, false);
93 } else {
94 $this->inform("Automatically confirmed:\n\n$message");
95 return true;
96 }
97 }
98
99 // For CLI-Setup
100
101 public function printLicenseMessage(): void
102 {
103 if ($this->shouldSayYes() || ($this->in->hasOption("no-interaction") && $this->in->getOption("no-interaction"))) {
104 return;
105 }
106 $this->text(
107 " ILIAS Copyright (C) 1998-2019 ILIAS Open Source e.V. - GPLv3\n\n" .
108 "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" .
109 "and you are welcome to redistribute it under certain conditions. Look\n" .
110 "into the LICENSE file for details."
111 );
112 }
113
114 protected function shouldSayYes(): bool
115 {
116 return $this->in->getOption("yes") ?? false;
117 }
118
119 public function title(string $title): void
120 {
121 $this->style->title($title);
122 }
123
124 public function success(string $text): void
125 {
126 $this->style->success($text);
127 }
128
129 public function error(string $text): void
130 {
131 $this->style->error($text);
132 }
133
134 public function text(string $text): void
135 {
136 $this->style->text($text);
137 }
138
139 public function startObjective(string $label, bool $is_notable): void
140 {
141 $this->last_objective_was_notable = $is_notable;
142 $this->last_objective_label = $label;
143 $this->output_in_objective = false;
144 if ($this->showLastObjectiveLabel()) {
145 $this->style->write(str_pad($label . "...", self::LABEL_WIDTH));
146 }
147 }
148
149 public function finishedLastObjective(): void
150 {
151 if ($this->output_in_objective) {
152 $this->startObjective($this->last_objective_label, $this->last_objective_was_notable);
153 }
154
155 if ($this->showLastObjectiveLabel()) {
156 $this->style->write("[<fg=green>OK</>]\n");
157 }
158 }
159
160 public function failedLastObjective(): void
161 {
162 // Always show label of failed objectives.
163 if ($this->output_in_objective || !$this->last_objective_was_notable) {
164 $this->startObjective($this->last_objective_label, true);
165 }
166
167 if ($this->showLastObjectiveLabel()) {
168 $this->style->write("[<fg=red>FAILED</>]\n");
169 }
170 }
171
172 protected function outputInObjective(): void
173 {
174 if (!$this->output_in_objective && $this->showLastObjectiveLabel()) {
175 $this->output_in_objective = true;
176 $this->style->write("[in progress]\n");
177 }
178 }
179
180 protected function showLastObjectiveLabel(): bool
181 {
182 return $this->last_objective_was_notable
183 || $this->out->isVeryVerbose()
184 || $this->out->isDebug();
185 }
186
187 public function isVerbose(): bool
188 {
189 return $this->out->isVerbose();
190 }
191}
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:33
inform(string $message)
Definition: IOWrapper.php:67
confirmExplicit(string $message, string $type_text_to_confirm)
Definition: IOWrapper.php:73
OutputInterface $out
Definition: IOWrapper.php:38
__construct(InputInterface $in, OutputInterface $out)
Definition: IOWrapper.php:44
confirmOrDeny(string $message)
Definition: IOWrapper.php:88
title(string $title)
Definition: IOWrapper.php:119
InputInterface $in
Definition: IOWrapper.php:37
startObjective(string $label, bool $is_notable)
Definition: IOWrapper.php:139
This defines ways in which objectives may interact with admins during the setup.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:31