1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Turahe\LaravelInstaller\Helpers; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Support\Facades\Artisan; |
7
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class FinalInstallManager. |
11
|
|
|
*/ |
12
|
|
|
class FinalInstallManager |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Run final commands. |
16
|
|
|
* |
17
|
|
|
* @return string |
18
|
|
|
*/ |
19
|
|
|
public function runFinal(): string |
20
|
|
|
{ |
21
|
|
|
$outputLog = new BufferedOutput; |
22
|
|
|
|
23
|
|
|
$this->generateKey($outputLog); |
24
|
|
|
$this->publishVendorAssets($outputLog); |
25
|
|
|
|
26
|
|
|
return $outputLog->fetch(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Generate New Application Key. |
31
|
|
|
* |
32
|
|
|
* @param BufferedOutput $outputLog |
33
|
|
|
* @return array|BufferedOutput |
34
|
|
|
*/ |
35
|
|
|
private static function generateKey(BufferedOutput $outputLog) |
36
|
|
|
{ |
37
|
|
|
try { |
38
|
|
|
if (config('installer.final.key')) { |
39
|
|
|
Artisan::call('key:generate', ['--force'=> true], $outputLog); |
40
|
|
|
} |
41
|
|
|
} catch (Exception $e) { |
42
|
|
|
return static::response($e->getMessage(), $outputLog); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $outputLog; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Publish vendor assets. |
50
|
|
|
* |
51
|
|
|
* @param BufferedOutput $outputLog |
52
|
|
|
* @return array|BufferedOutput |
53
|
|
|
*/ |
54
|
|
|
private static function publishVendorAssets(BufferedOutput $outputLog) |
55
|
|
|
{ |
56
|
|
|
try { |
57
|
|
|
if (config('installer.final.publish')) { |
58
|
|
|
Artisan::call('vendor:publish', ['--all' => true], $outputLog); |
59
|
|
|
} |
60
|
|
|
} catch (Exception $e) { |
61
|
|
|
return static::response($e->getMessage(), $outputLog); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $outputLog; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return a formatted error messages. |
69
|
|
|
* |
70
|
|
|
* @param $message |
71
|
|
|
* @param BufferedOutput $outputLog |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
private static function response($message, BufferedOutput $outputLog) |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
'status' => 'error', |
78
|
|
|
'message' => $message, |
79
|
|
|
'dbOutputLog' => $outputLog->fetch(), |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|