1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the box project. |
7
|
|
|
* |
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
9
|
|
|
* Théo Fidry <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This source file is subject to the MIT license that is bundled |
12
|
|
|
* with this source code in the file LICENSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace KevinGH\Box\Logger; |
16
|
|
|
|
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
20
|
|
|
|
21
|
|
|
final class BuildLogger |
22
|
|
|
{ |
23
|
|
|
public const QUESTION_MARK_PREFIX = '?'; |
24
|
|
|
public const STAR_PREFIX = '*'; |
25
|
|
|
public const PLUS_PREFIX = '+'; |
26
|
|
|
public const MINUS_PREFIX = '-'; |
27
|
|
|
public const CHEVRON_PREFIX = '>'; |
28
|
|
|
|
29
|
|
|
private $io; |
30
|
|
|
|
31
|
|
|
public function __construct(SymfonyStyle $io) |
32
|
|
|
{ |
33
|
|
|
$this->io = $io; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function log(string $prefix, string $message, int $verbosity = OutputInterface::OUTPUT_NORMAL): void |
37
|
|
|
{ |
38
|
|
|
switch ($prefix) { |
39
|
|
|
case '!': |
40
|
|
|
$prefix = "<error>$prefix</error>"; |
41
|
|
|
break; |
42
|
|
|
case self::STAR_PREFIX: |
43
|
|
|
$prefix = "<info>$prefix</info>"; |
44
|
|
|
break; |
45
|
|
|
case self::QUESTION_MARK_PREFIX: |
46
|
|
|
$prefix = "<comment>$prefix</comment>"; |
47
|
|
|
break; |
48
|
|
|
case self::PLUS_PREFIX: |
49
|
|
|
case self::MINUS_PREFIX: |
50
|
|
|
$prefix = " <comment>$prefix</comment>"; |
51
|
|
|
break; |
52
|
|
|
case self::CHEVRON_PREFIX: |
53
|
|
|
$prefix = " <comment>$prefix</comment>"; |
54
|
|
|
break; |
55
|
|
|
default: |
56
|
|
|
throw new InvalidArgumentException('Expected one of the logger constant as a prefix.'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->io->writeln( |
60
|
|
|
"$prefix $message", |
61
|
|
|
$verbosity |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function logStartBuilding(string $path): void |
66
|
|
|
{ |
67
|
|
|
$message = sprintf( |
68
|
|
|
'Building the PHAR "<comment>%s</comment>"', |
69
|
|
|
$path |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
if ($this->io->isVerbose()) { |
73
|
|
|
$this->log( |
74
|
|
|
self::STAR_PREFIX, |
75
|
|
|
$message |
76
|
|
|
); |
77
|
|
|
} else { |
78
|
|
|
$this->io->writeln($message); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|