|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
|
|
8
|
|
|
class ConfigCommand extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The console command name. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $signature = 'admin:config {path?}'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Compare the difference between the admin config file and the original'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function handle() |
|
28
|
|
|
{ |
|
29
|
|
|
$path = $this->argument('path') ?: 'config/admin.php'; |
|
30
|
|
|
|
|
31
|
|
|
$current = require $path; |
|
32
|
|
|
$original = require __DIR__.'/../../config/admin.php'; |
|
33
|
|
|
|
|
34
|
|
|
$added = $this->diff($current, $original); |
|
35
|
|
|
$removed = $this->diff($original, $current); |
|
36
|
|
|
|
|
37
|
|
|
if ($added->isEmpty() && $removed->isEmpty()) { |
|
38
|
|
|
$this->info('Configuration items have not been modified'); |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->line("The admin config file `$path`:"); |
|
43
|
|
|
|
|
44
|
|
|
$this->printDiff('Added', $added); |
|
45
|
|
|
$this->printDiff('Removed', $removed, true); |
|
46
|
|
|
|
|
47
|
|
|
$this->line(''); |
|
48
|
|
|
$this->comment('Please open `vendor/encore/laravel-admin/config/admin.php` to check the difference'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function diff(array $from, array $to) |
|
52
|
|
|
{ |
|
53
|
|
|
return collect(Arr::dot($from)) |
|
|
|
|
|
|
54
|
|
|
->keys() |
|
55
|
|
|
->reject(function ($key) use ($to) { |
|
56
|
|
|
return Arr::has($to, $key); |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function printDiff($title, $diff, $error = false) |
|
61
|
|
|
{ |
|
62
|
|
|
if ($diff->isEmpty()) { |
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$this->line(''); |
|
67
|
|
|
$this->comment("{$title}:"); |
|
68
|
|
|
|
|
69
|
|
|
$diff->each(function ($key) use ($error) { |
|
70
|
|
|
if ($error) { |
|
71
|
|
|
$this->error(" {$key}"); |
|
72
|
|
|
} else { |
|
73
|
|
|
$this->info(" {$key}"); |
|
74
|
|
|
} |
|
75
|
|
|
}); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: