7
7
use Illuminate \Console \Scheduling \Schedule ;
8
8
use Laminas \Text \Figlet \Figlet ;
9
9
use LaravelZero \Framework \Commands \Command ;
10
+ use App \Helpers \Webzone ;
11
+ use App \Helpers \Downloader ;
12
+ use Illuminate \Support \Facades \Storage ;
10
13
11
14
class Symfony extends Command
12
15
{
13
- protected $ symfony ;
16
+ protected static $ symfony ;
14
17
15
- protected $ dir ;
18
+ protected static $ dir ;
19
+
20
+ protected static $ cliName = 'symfony ' ;
21
+
22
+ protected static $ disk ;
23
+
24
+ protected static $ link ;
25
+
26
+ protected static string $ needle = 'Symfony CLI version ' ;
16
27
17
28
/**
18
29
* The signature of the command.
@@ -26,49 +37,61 @@ class Symfony extends Command
26
37
*
27
38
* @var string
28
39
*/
29
- protected $ description = 'Install Symfony Installer ' ;
30
-
40
+ protected $ description = 'Install Symfony CLI ' ;
41
+
42
+ public function __construct ()
43
+ {
44
+ parent ::__construct ();
45
+
46
+ $ this ->webzone = new Webzone ();
47
+ }
48
+
31
49
/**
32
50
* Execute the console command.
33
51
*/
34
52
public function handle (): void
35
53
{
36
54
$ this ->callSilently ('settings:init ' );
37
- $ this ->symfony = config ('symfony.PATH ' );
38
- $ this ->dir = '/data/data/com.termux/files/usr/bin ' ;
55
+
56
+ self ::setConfigs ();
57
+
39
58
$ this ->install ();
40
59
}
60
+
61
+ public static function setConfigs ()
62
+ {
63
+ static ::$ symfony = config ('symfony.CLI_PATH ' );
64
+ static ::$ dir = config ('symfony.PATH ' , '/data/data/com.termux/files/usr/bin ' );
65
+ static ::$ link = config ('symfony.CLI_DOWNLOAD_LINK ' );
66
+ }
41
67
42
68
public function install ()
43
69
{
44
70
if ($ this ->checkInstallation ()) {
45
71
$ this ->error ('Symfony CLI is already installed. Use "symfony help" to show all commands. ' );
46
- return false ;
72
+ return 1 ;
47
73
}
48
74
49
- $ this ->info (exec ('clear ' ));
50
- $ this ->logo ();
51
- $ this ->comment ("\nInstalling Symfony CLI... \n" );
52
- $ link = config ('symfony.CLI_DOWNLOAD_LINK ' );
53
- $ lines = shell_exec ("curl -w ' \n%{http_code} \n' {$ link } -o {$ this ->symfony } && chmod +x {$ this ->symfony }" );
54
- $ lines = explode ("\n" , trim ($ lines ));
55
- $ status = $ lines [count ($ lines ) - 1 ];
56
- $ this ->checkDownloadStatus ($ status , $ this ->dir );
75
+ $ this ->webzone ->clear ();
76
+
77
+ $ this ->webzone ->logo ('Symfony ' , 'comment ' );
78
+
79
+ $ this ->newline ();
80
+ $ this ->comment ("Installing Symfony CLI... " );
81
+ $ this ->newline ();
82
+
83
+ $ this ->runTasks ();
84
+
57
85
}
58
86
59
87
public function checkInstallation (): bool
60
88
{
61
- if (file_exists ($ this -> symfony )) {
89
+ if (file_exists (static :: $ symfony )) {
62
90
return true ;
63
91
}
64
92
return false ;
65
93
}
66
94
67
- public function logo (): void
68
- {
69
- $ figlet = new Figlet ();
70
- $ this ->comment ($ figlet ->setFont (config ('logo.font ' ))->render ('Symfony ' ));
71
- }
72
95
73
96
/**
74
97
* Define the command's schedule.
@@ -78,30 +101,34 @@ public function schedule(Schedule $schedule): void
78
101
// $schedule->command(static::class)->everyMinute();
79
102
}
80
103
81
- private function checkDownloadStatus ($ status , $ dir ): void
82
- {
83
- switch ($ status ) {
84
- case 000 :
85
- $ this ->error ('Cannot connect to Server ' );
86
- break ;
87
- case 200 :
88
- $ this ->comment ("\nDownloaded Successfully...!!! " );
89
- $ this ->runTasks ();
90
- break ;
91
- case 404 :
92
- $ this ->error ('File not found on server.. ' );
93
- break ;
94
- default :
95
- $ this ->error ('An Unknown Error occurred... ' );
96
- }
97
- }
98
-
99
104
private function runTasks (): void
100
105
{
106
+ $ this ->download ();
107
+
108
+ $ this ->task ('setting permissions ' , function () {
109
+ return chmod (static ::$ symfony , 0775 );
110
+ });
111
+
101
112
$ this ->task ('verifying command ' , function () {
102
- if (file_exists ($ this ->symfony )) {
113
+ return (str_contains (shell_exec ('symfony version ' ), static ::$ needle ) && file_exists (static ::$ symfony ));
114
+ });
115
+ }
116
+
117
+ private function download (): void
118
+ {
119
+ static ::$ disk = Storage::build ([
120
+ 'driver ' => 'local ' ,
121
+ 'root ' => static ::$ dir ,
122
+ ]);
123
+
124
+ $ downloadTask = $ this ->task ('Downloading resources ' , function () {
125
+ $ this ->downloader = new Downloader (static ::$ link , static ::$ cliName , static ::$ disk );
126
+ $ response = $ this ->downloader ->download ();
127
+
128
+ if ($ response ['ok ' ]) {
103
129
return true ;
104
130
}
131
+ $ this ->error ($ response ['error ' ]->getMessage ());
105
132
return false ;
106
133
});
107
134
}
0 commit comments