1
|
|
|
<?php namespace jlourenco\support\Commands; |
2
|
|
|
|
3
|
|
|
use Illuminate\Console\Command; |
4
|
|
|
use Symfony\Component\Console\Input\InputOption; |
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use File; |
7
|
|
|
use jlourenco\support\Helpers\FileLoader; |
8
|
|
|
use Setting; |
9
|
|
|
use Schema; |
10
|
|
|
|
11
|
|
View Code Duplication |
class ConfigCommand extends Command { |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The console command name. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'jlourenco:config'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Command to setup all the configurations for the jlourenco packages'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new command instance. |
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the console command. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function fire() |
41
|
|
|
{ |
42
|
|
|
if (!$this->confirm('Running this command will reset all jlourenco config files. Are you sure? ')) |
43
|
|
|
{ |
44
|
|
|
$this->info('Command was aborted by the user.'); |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->compileConfigFiles(); |
49
|
|
|
// $this->checkSentinelConfigFiles(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$this->info('Command ran successfully'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function compileConfigFiles() |
55
|
|
|
{ |
56
|
|
|
$path = base_path('/config'); |
57
|
|
|
$mainFile = $path . '/jlourenco.php'; |
58
|
|
|
$fileExists = file_exists($mainFile); |
59
|
|
|
|
60
|
|
|
$files = array_filter(scandir($path), function ($var) { |
61
|
|
|
return (!(stripos($var, 'jlourenco.') === false) && $var != 'jlourenco.php'); |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
if ($fileExists) |
65
|
|
|
unlink($mainFile); |
66
|
|
|
|
67
|
|
|
touch($mainFile); |
68
|
|
|
|
69
|
|
|
$content = "<?php\n"; |
70
|
|
|
$content .= "return [\n\n"; |
71
|
|
|
|
72
|
|
|
foreach ($files as $file) |
73
|
|
|
{ |
74
|
|
|
$in = fopen($path . '/' . $file, "r"); |
75
|
|
|
|
76
|
|
|
while ($line = fgets($in)) |
77
|
|
|
{ |
78
|
|
|
if ((stripos($line, '<?php') === false) && (stripos($line, '];') === false) && (stripos($line, 'return [') === false)) |
79
|
|
|
$content .= $line; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
fclose($in); |
83
|
|
|
|
84
|
|
|
unlink($path . '/' . $file); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$content .= "];\n"; |
88
|
|
|
|
89
|
|
|
$bytesWritten = File::append($mainFile, $content); |
90
|
|
|
|
91
|
|
|
if ($bytesWritten === false) |
92
|
|
|
$this->info('Couldn\'t write to config file.'); |
93
|
|
|
|
94
|
|
|
$this->info('Config files compiled'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private function checkSentinelConfigFiles() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
Setting::set('cartalyst.sentinel.users.model', 'jlourenco\base\Models\BaseUser'); |
100
|
|
|
Setting::set('cartalyst.sentinel.roles.model', 'jlourenco\base\Models\Group'); |
101
|
|
|
|
102
|
|
|
/* |
|
|
|
|
103
|
|
|
$l = new FileLoader( |
104
|
|
|
new \Illuminate\Filesystem\Filesystem(), |
105
|
|
|
base_path().'/config/cartalyst.sentinel.php' |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$conf = ['' => '']; |
109
|
|
|
$conf2 = ['cartalyst.sentinel.roles.model' => 'jlourenco\base\Models\Group']; |
110
|
|
|
|
111
|
|
|
$l->save($conf, '', 'cartalyst.sentinel'); |
112
|
|
|
*/ |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.