1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zoutapps\Laravel\Backpack\Branding\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Console\ConfirmableTrait; |
7
|
|
|
use Zoutapps\Laravel\Backpack\Branding\Services\BackpackBaseConfigService; |
8
|
|
|
use Zoutapps\Laravel\Backpack\Branding\Services\CopyService; |
9
|
|
|
use Zoutapps\Laravel\Backpack\Branding\Services\EnvService; |
10
|
|
|
use Zoutapps\Laravel\Backpack\Branding\Services\BrandingService; |
11
|
|
|
|
12
|
|
|
class BrandingCommand extends Command |
13
|
|
|
{ |
14
|
|
|
use ConfirmableTrait; |
15
|
|
|
|
16
|
|
|
protected $signature = 'za:brand |
17
|
|
|
{path? : the path where your branding defaults are} |
18
|
|
|
{--no-env : Skip setting .env values} |
19
|
|
|
{--no-config : Skip setting config values} |
20
|
|
|
{--no-copy : Skip copying the specified files} |
21
|
|
|
{--no-helper : Skip setting up the Branding Facade} |
22
|
|
|
{--force : Force the operation to run when in production}'; |
23
|
|
|
|
24
|
|
|
protected $description = 'Brand your fresh Laravel-Backpack installation'; |
25
|
|
|
|
26
|
|
|
public $defaultsPath; |
27
|
|
|
|
28
|
|
|
private $defaults; |
29
|
|
|
|
30
|
|
|
public function handle() |
31
|
|
|
{ |
32
|
|
|
if (!$this->confirmToProceed()) { |
33
|
|
|
return false; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if ($path = $this->argument('path')) { |
37
|
|
|
|
38
|
|
|
if (!$fullPath = realpath($path)) { |
39
|
|
|
$this->error('Provided defaults path <comment>'.$fullPath.'</comment> does not exist.'); |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->defaultsPath = $fullPath; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (!$this->option('no-env')) { |
47
|
|
|
$envService = new EnvService($this, $this->envPath()); |
48
|
|
|
$envService->perform(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (!$this->option('no-config')) { |
52
|
|
|
$baseConfigService = new BackpackBaseConfigService($this, $this->laravel->basePath('config/backpack/base.php')); |
|
|
|
|
53
|
|
|
$baseConfigService->perform(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if(!$this->option('no-copy')) { |
57
|
|
|
$copyService = new CopyService($this); |
58
|
|
|
$copyService->perform(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!$this->option('no-helper')) { |
62
|
|
|
$helperService = new BrandingService($this); |
63
|
|
|
$helperService->perform(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @noinspection PhpDocMissingThrowsInspection */ |
68
|
|
|
/** |
69
|
|
|
* @param string|null $key |
70
|
|
|
* |
71
|
|
|
* @return \Illuminate\Support\Collection |
72
|
|
|
*/ |
73
|
|
|
public function getDefaults($key = null) |
74
|
|
|
{ |
75
|
|
|
if (!$this->defaults && $this->defaultsPath) { |
76
|
|
|
$content = file_get_contents($this->defaultsPath . '/defaults.json'); |
77
|
|
|
$assoc = json_decode($content, true); |
78
|
|
|
|
79
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) { |
80
|
|
|
$this->error('Provided defaults.json does not contain valid json.'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->defaults = collect($assoc); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $key ? collect($this->defaults[$key] ?? null) : $this->defaults; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the .env file path. |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
protected function envPath() |
95
|
|
|
{ |
96
|
|
|
if (method_exists($this->laravel, 'environmentFilePath')) { |
97
|
|
|
return $this->laravel->environmentFilePath(); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
return $this->laravel->basePath('.env'); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.