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