|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace SetBased\Stratum\Backend; |
|
5
|
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Output decorator based on Symfony Style Guide. |
|
13
|
|
|
*/ |
|
14
|
|
|
class StratumStyle extends SymfonyStyle |
|
15
|
|
|
{ |
|
16
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
17
|
|
|
/** |
|
18
|
|
|
* @inheritdoc |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(InputInterface $input, OutputInterface $output) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($input, $output); |
|
23
|
|
|
|
|
24
|
|
|
// Create style notes. |
|
25
|
|
|
$style = new OutputFormatterStyle('yellow'); |
|
26
|
|
|
$output->getFormatter()->setStyle('note', $style); |
|
27
|
|
|
|
|
28
|
|
|
// Create style for database objects. |
|
29
|
|
|
$style = new OutputFormatterStyle('green', null, ['bold']); |
|
30
|
|
|
$output->getFormatter()->setStyle('dbo', $style); |
|
31
|
|
|
|
|
32
|
|
|
// Create style for file and directory names. |
|
33
|
|
|
$style = new OutputFormatterStyle(null, null, ['bold']); |
|
34
|
|
|
$output->getFormatter()->setStyle('fso', $style); |
|
35
|
|
|
|
|
36
|
|
|
// Create style for SQL statements. |
|
37
|
|
|
$style = new OutputFormatterStyle('magenta', null, ['bold']); |
|
38
|
|
|
$output->getFormatter()->setStyle('sql', $style); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
42
|
|
|
/** |
|
43
|
|
|
* Logs a message according to a format string at verbosity level OutputInterface::VERBOSITY_NORMAL. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $format The format string, see sprintf. |
|
46
|
|
|
* @param mixed ...$values The values. |
|
47
|
|
|
* |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
public function logDebug(string $format, mixed ...$values): void |
|
51
|
|
|
{ |
|
52
|
|
|
if ($this->getVerbosity()>=OutputInterface::VERBOSITY_DEBUG) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->writeln(vsprintf('<info>'.$format.'</info>', $values)); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
59
|
|
|
/** |
|
60
|
|
|
* Logs a message according to a format string at verbosity level OutputInterface::VERBOSITY_NORMAL. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $format The format string, see sprintf. |
|
63
|
|
|
* @param mixed ...$values The values. |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function logInfo(string $format, mixed ...$values): void |
|
68
|
|
|
{ |
|
69
|
|
|
if ($this->getVerbosity()>=OutputInterface::VERBOSITY_NORMAL) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->writeln(vsprintf('<info>'.$format.'</info>', $values)); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
76
|
|
|
/** |
|
77
|
|
|
* Logs a message according to a format string at verbosity level OutputInterface::VERBOSITY_NORMAL. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $format The format string, see sprintf. |
|
80
|
|
|
* @param mixed ...$values The values. |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function logNote(string $format, mixed ...$values): void |
|
85
|
|
|
{ |
|
86
|
|
|
if ($this->getVerbosity()>=OutputInterface::VERBOSITY_NORMAL) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->writeln('<note> ! [NOTE] '.vsprintf($format, $values).'</note>'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
93
|
|
|
/** |
|
94
|
|
|
* Logs a message according to a format string at verbosity level OutputInterface::VERBOSITY_VERBOSE. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $format The format string, see sprintf. |
|
97
|
|
|
* @param mixed ...$values The values. |
|
98
|
|
|
* |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public function logVerbose(string $format, mixed ...$values): void |
|
102
|
|
|
{ |
|
103
|
|
|
if ($this->getVerbosity()>=OutputInterface::VERBOSITY_VERBOSE) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->writeln(vsprintf('<info>'.$format.'</info>', $values)); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
110
|
|
|
/** |
|
111
|
|
|
* Logs a message according to a format string at verbosity level OutputInterface::VERBOSITY_VERY_VERBOSE. |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $format The format string, see sprintf. |
|
114
|
|
|
* @param mixed ...$values The values. |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function logVeryVerbose(string $format, mixed ...$values): void |
|
119
|
|
|
{ |
|
120
|
|
|
if ($this->getVerbosity()>=OutputInterface::VERBOSITY_VERY_VERBOSE) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->writeln(vsprintf('<info>'.$format.'</info>', $values)); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
|
130
|
|
|
|