ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
IOWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 namespace ILIAS\Setup\CLI;
6 
11 
16 class IOWrapper implements AdminInteraction
17 {
18  const LABEL_WIDTH = 75;
19  const ELLIPSIS = "...";
20 
24  protected $in;
25 
29  protected $out;
30 
34  protected $say_yes;
35 
36 
40  protected $style;
41 
45  protected $last_objective_was_notable = false;
46 
50  protected $last_objective_label = "";
51 
55  protected $output_in_objective = false;
56 
57  public function __construct(InputInterface $in, OutputInterface $out, bool $say_yes = false)
58  {
59  $this->in = $in;
60  $this->out = $out;
61  $this->style = new SymfonyStyle($in, $out);
62  $this->say_yes = $say_yes;
63  }
64 
65  // Implementation of AdminInteraction
66 
67  public function inform(string $message) : void
68  {
69  $this->outputInObjective();
70  $this->style->note($message);
71  }
72 
73  public function confirmOrDeny(string $message) : bool
74  {
75  $this->outputInObjective();
76  if (!$this->say_yes) {
77  return $this->style->confirm($message, false);
78  } else {
79  $this->inform("Automatically confirmed:\n\n$message");
80  return true;
81  }
82  }
83 
84  // For CLI-Setup
85 
86  public function title(string $title) : void
87  {
88  $this->style->title($title);
89  }
90 
91  public function success(string $text) : void
92  {
93  $this->style->success($text);
94  }
95 
96  public function error(string $text) : void
97  {
98  $this->style->error($text);
99  }
100 
101  public function text(string $text) : void
102  {
103  $this->style->text($text);
104  }
105 
106  public function startObjective(string $label, bool $is_notable)
107  {
108  $this->last_objective_was_notable = $is_notable;
109  $this->last_objective_label = $label;
110  $this->output_in_objective = false;
111  if ($this->showLastObjectiveLabel()) {
112  $this->style->write(str_pad($label . "...", self::LABEL_WIDTH));
113  }
114  }
115 
116  public function finishedLastObjective()
117  {
118  if ($this->output_in_objective) {
119  $this->startObjective($this->last_objective_label, $this->last_objective_was_notable);
120  }
121 
122  if ($this->showLastObjectiveLabel()) {
123  $this->style->write("[<fg=green>OK</>]\n");
124  }
125  }
126 
127  public function failedLastObjective()
128  {
129  // Always show label of failed objectives.
130  if ($this->output_in_objective || !$this->last_objective_was_notable) {
131  $this->startObjective($this->last_objective_label, true);
132  }
133 
134  if ($this->showLastObjectiveLabel()) {
135  $this->style->write("[<fg=red>FAILED</>]\n");
136  }
137  }
138 
139  protected function outputInObjective() : void
140  {
141  if (!$this->output_in_objective && $this->showLastObjectiveLabel()) {
142  $this->output_in_objective = true;
143  $this->style->write("[in progress]\n");
144  }
145  }
146 
147  protected function showLastObjectiveLabel()
148  {
149  return $this->last_objective_was_notable
150  || $this->out->isVeryVerbose()
151  || $this->out->isDebug();
152  }
153 }
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:16
startObjective(string $label, bool $is_notable)
Definition: IOWrapper.php:106
__construct(InputInterface $in, OutputInterface $out, bool $say_yes=false)
Definition: IOWrapper.php:57
This defines ways in which objectives may interact with admins during the setup.
confirmOrDeny(string $message)
Definition: IOWrapper.php:73
title(string $title)
Definition: IOWrapper.php:86
success(string $text)
Definition: IOWrapper.php:91
$message
Definition: xapiexit.php:14
inform(string $message)
Definition: IOWrapper.php:67