1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Laravel-Env-Sync |
4
|
|
|
* |
5
|
|
|
* @author Julien Tant - Craftyx <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Jtant\LaravelEnvSync\Console; |
9
|
|
|
|
10
|
|
|
use Illuminate\Console\Command; |
11
|
|
|
use Jtant\LaravelEnvSync\Reader\ReaderInterface; |
12
|
|
|
use Jtant\LaravelEnvSync\SyncService; |
13
|
|
|
|
14
|
|
|
class DiffCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $signature = 'env:diff'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'Show the difference between env files'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ReaderInterface |
32
|
|
|
*/ |
33
|
|
|
private $reader; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create a new command instance. |
38
|
|
|
* |
39
|
|
|
* @param ReaderInterface $reader |
40
|
|
|
*/ |
41
|
|
|
public function __construct(ReaderInterface $reader) |
42
|
|
|
{ |
43
|
|
|
parent::__construct(); |
44
|
|
|
$this->reader = $reader; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Execute the console command. |
49
|
|
|
* |
50
|
|
|
* @return mixed |
51
|
|
|
*/ |
52
|
|
|
public function handle() |
53
|
|
|
{ |
54
|
|
|
$env = base_path('.env'); |
55
|
|
|
$example = base_path('.env.example'); |
56
|
|
|
|
57
|
|
|
$envValues = $this->reader->read($env); |
58
|
|
|
$exampleValues = $this->reader->read($example); |
59
|
|
|
|
60
|
|
|
$keys = array_unique(array_merge(array_keys($envValues), array_keys($exampleValues))); |
61
|
|
|
sort($keys); |
62
|
|
|
|
63
|
|
|
$header = ["Key", basename($env), basename($example)]; |
64
|
|
|
$lines = []; |
65
|
|
|
foreach ($keys as $key) { |
66
|
|
|
$envVal = isset($envValues[$key]) ? $envValues[$key] : '<error>NOT FOUND</error>'; |
67
|
|
|
$exampleVal = isset($exampleValues[$key]) ? $exampleValues[$key] : '<error>NOT FOUND</error>'; |
68
|
|
|
$lines[] = [$key, $envVal, $exampleVal]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->table($header, $lines); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|