1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\Laravel\Support\Services\Optimus; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Jenssegers\Optimus\Energon; |
8
|
|
|
|
9
|
|
|
class GenerateOptimusCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'support:generate-optimus |
17
|
|
|
{--show : Display the values instead of modifying files}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Generate Optimus values'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Execute the console command. |
28
|
|
|
* |
29
|
|
|
* @return mixed |
30
|
|
|
*/ |
31
|
|
|
public function handle() |
32
|
|
|
{ |
33
|
|
|
$values = array_combine(['prime', 'inverse', 'random'], Energon::generate()); |
34
|
|
|
|
35
|
|
|
if ($this->option('show')) { |
36
|
|
|
return $this->printValues($values); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$this->setValuesInEnvironmentFile($values); |
40
|
|
|
|
41
|
|
|
$this->laravel['config']['support.optimus'] = $values; |
42
|
|
|
|
43
|
|
|
$this->printValues($values); |
44
|
|
|
|
45
|
|
|
$this->info('Optimus values set successfully.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Print Optimus values. |
50
|
|
|
* |
51
|
|
|
* @param array $values |
52
|
|
|
*/ |
53
|
|
|
protected function printValues($values) |
54
|
|
|
{ |
55
|
|
|
$this->table(array_keys($values), [array_values($values)]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set Optimus values in the environment file. |
60
|
|
|
* |
61
|
|
|
* @param array $values |
62
|
|
|
*/ |
63
|
|
|
protected function setValuesInEnvironmentFile($values) |
64
|
|
|
{ |
65
|
|
|
$content = file_get_contents($this->laravel->environmentFilePath()); |
|
|
|
|
66
|
|
|
|
67
|
|
|
foreach ($values as $key => $value) { |
68
|
|
|
$name = 'OPTIMUS_'.strtoupper($key); |
69
|
|
|
$text = "{$name}={$value}"; |
70
|
|
|
|
71
|
|
|
$content = preg_replace("#{$name}=.*#", $text, $content, -1, $replaceCount); |
72
|
|
|
|
73
|
|
|
if (0 === $replaceCount) { |
74
|
|
|
$content .= $text.PHP_EOL; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
file_put_contents($this->laravel->environmentFilePath(), $content); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.