humbug /
box
| 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\Console\Logger; |
||
| 16 | |||
| 17 | use Fidry\Console\IO; |
||
| 18 | use InvalidArgumentException; |
||
| 19 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 20 | use function sprintf; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @internal |
||
| 24 | */ |
||
| 25 | final readonly class CompilerLogger |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 26 | { |
||
| 27 | public const QUESTION_MARK_PREFIX = '?'; |
||
| 28 | public const STAR_PREFIX = '*'; |
||
| 29 | public const PLUS_PREFIX = '+'; |
||
| 30 | public const MINUS_PREFIX = '-'; |
||
| 31 | public const CHEVRON_PREFIX = '>'; |
||
| 32 | |||
| 33 | public function __construct(private IO $io) |
||
| 34 | { |
||
| 35 | } |
||
| 36 | |||
| 37 | public function getIO(): IO |
||
| 38 | { |
||
| 39 | return $this->io; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function log(string $prefix, string $message, int $verbosity = OutputInterface::OUTPUT_NORMAL): void |
||
| 43 | { |
||
| 44 | $prefix = match ($prefix) { |
||
| 45 | '!' => "<error>{$prefix}</error>", |
||
| 46 | self::STAR_PREFIX => "<info>{$prefix}</info>", |
||
| 47 | self::QUESTION_MARK_PREFIX => "<comment>{$prefix}</comment>", |
||
| 48 | self::PLUS_PREFIX, self::MINUS_PREFIX => " <comment>{$prefix}</comment>", |
||
| 49 | self::CHEVRON_PREFIX => " <comment>{$prefix}</comment>", |
||
| 50 | default => throw new InvalidArgumentException('Expected one of the logger constant as a prefix.'), |
||
| 51 | }; |
||
| 52 | |||
| 53 | $this->io->writeln( |
||
| 54 | "{$prefix} {$message}", |
||
| 55 | $verbosity, |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function logStartBuilding(string $path): void |
||
| 60 | { |
||
| 61 | $this->io->writeln( |
||
| 62 | sprintf( |
||
| 63 | '🔨 Building the PHAR "<comment>%s</comment>"', |
||
| 64 | $path, |
||
| 65 | ), |
||
| 66 | ); |
||
| 67 | $this->io->newLine(); |
||
| 68 | } |
||
| 69 | } |
||
| 70 |