|
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
|
|
|
|
|
8
|
|
|
class SetupCommand extends Command { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The console command name. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $name = 'jlourenco:setup'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The console command description. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $description = 'Command to setup all the requirements for the jlourenco packages'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new command instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Execute the console command. |
|
36
|
|
|
* |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
public function fire() |
|
40
|
|
|
{ |
|
41
|
|
|
if (!$this->confirm('Running this command will reset all jlourenco config files. Are you sure? ')) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->info('Command was aborted by the user.'); |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->compileConfigFiles(); |
|
48
|
|
|
|
|
49
|
|
|
$this->info('Command ran successfully'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function compileConfigFiles() |
|
53
|
|
|
{ |
|
54
|
|
|
$path = base_path('/config'); |
|
55
|
|
|
$mainFile = $path . '/jlourenco.php'; |
|
56
|
|
|
$fileExists = file_exists($mainFile); |
|
57
|
|
|
|
|
58
|
|
|
$files = array_filter(scandir($path), function ($var) { |
|
59
|
|
|
return (!(stripos($var, 'jlourenco.') === false) && $var != 'jlourenco.php'); |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
if ($fileExists) |
|
63
|
|
|
unlink($mainFile); |
|
64
|
|
|
|
|
65
|
|
|
touch($mainFile); |
|
66
|
|
|
|
|
67
|
|
|
$content = "<?php\n"; |
|
68
|
|
|
$content .= "return [\n\n"; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($files as $file) |
|
71
|
|
|
{ |
|
72
|
|
|
$in = fopen($path . '/' . $file, "r"); |
|
73
|
|
|
|
|
74
|
|
|
while ($line = fgets($in)) |
|
75
|
|
|
{ |
|
76
|
|
|
if ((stripos($line, '<?php') === false) && (stripos($line, '];') === false) && (stripos($line, 'return [') === false)) |
|
77
|
|
|
$content .= $line; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
fclose($in); |
|
81
|
|
|
|
|
82
|
|
|
unlink($path . '/' . $file); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$content .= "];\n"; |
|
86
|
|
|
|
|
87
|
|
|
$bytesWritten = File::append($mainFile, $content); |
|
88
|
|
|
if ($bytesWritten === false) |
|
89
|
|
|
die("Couldn't write to config file."); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$this->info('Config files compiled'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.