1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Psh\Application; |
4
|
|
|
|
5
|
|
|
use League\CLImate\CLImate; |
6
|
|
|
use Shopware\Psh\Config\ConfigLogger; |
7
|
|
|
use function sprintf; |
8
|
|
|
use function str_replace; |
9
|
|
|
|
10
|
|
|
class ApplicationConfigLogger implements ConfigLogger |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $rootDirectory; |
16
|
|
|
|
17
|
|
|
private $output = []; |
18
|
|
|
|
19
|
|
|
public function __construct(string $rootDirectory) |
20
|
|
|
{ |
21
|
|
|
$this->rootDirectory = $rootDirectory; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function mainConfigFiles(string $mainFile, ?string $overrideFile = null): void |
25
|
|
|
{ |
26
|
|
|
if ($overrideFile === null) { |
27
|
|
|
$this->print(sprintf('Using %s', $this->cleanUpPath($mainFile))); |
28
|
|
|
|
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$this->print(sprintf( |
33
|
|
|
'Using %s extended by %s', |
34
|
|
|
$this->cleanUpPath($mainFile), |
35
|
|
|
$this->cleanUpPath($overrideFile) |
36
|
|
|
)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function notifyImportNotFound(string $import): void |
40
|
|
|
{ |
41
|
|
|
$this->print(sprintf(' -> NOTICE: No import found for path "%s"', $import)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function importConfigFiles(string $import, string $mainFile, ?string $overrideFile = null): void |
45
|
|
|
{ |
46
|
|
|
if ($overrideFile === null) { |
47
|
|
|
$this->print(sprintf(' -> Importing %s from "%s" ', $this->cleanUpPath($mainFile), $import)); |
48
|
|
|
|
49
|
|
|
return; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->print(sprintf( |
53
|
|
|
' -> Importing %s extended by %s from "%s"', |
54
|
|
|
$this->cleanUpPath($mainFile), |
55
|
|
|
$this->cleanUpPath($overrideFile), |
56
|
|
|
$import |
57
|
|
|
)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function cleanUpPath(string $configFile): string |
61
|
|
|
{ |
62
|
|
|
return str_replace($this->rootDirectory . '/', '', $configFile); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function print(string $message): void |
66
|
|
|
{ |
67
|
|
|
$this->output[] = $message; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function printOut(CLImate $cliMate): void |
71
|
|
|
{ |
72
|
|
|
foreach ($this->output as $message) { |
73
|
|
|
$cliMate->yellow()->out($message); |
74
|
|
|
} |
75
|
|
|
$cliMate->out(PHP_EOL); |
76
|
|
|
|
77
|
|
|
$this->output = []; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|