5
5
defined ('DS ' ) or exit ('No direct access. ' );
6
6
7
7
use System \Storage ;
8
+ use System \Console \Color ;
8
9
9
10
abstract class Provider
10
11
{
@@ -36,16 +37,16 @@ protected function zipball($url, array $package, $path)
36
37
}
37
38
38
39
if (is_dir (path ('package ' ) . $ package ['name ' ])) {
39
- echo PHP_EOL . $ this -> error (sprintf ('Package already downloaded: %s ' , $ package ['name ' ]));
40
+ echo PHP_EOL . Color:: red (sprintf ('Package already downloaded: %s ' , $ package ['name ' ]));
40
41
exit ;
41
42
}
42
43
43
44
chmod (Storage::latest (path ('package ' ))->getRealPath (), 0755 );
44
- echo PHP_EOL . $ this -> info ('Downloading zipball... ' , false );
45
+ echo PHP_EOL . Color:: green ('Downloading zipball... ' , false );
45
46
$ this ->download ($ url , $ zipball );
46
47
echo ' done! ' ;
47
48
48
- echo PHP_EOL . $ this -> info ('Extracting zipball... ' , false );
49
+ echo PHP_EOL . Color:: green ('Extracting zipball... ' , false );
49
50
50
51
static ::unzip ($ zipball , path ('package ' ));
51
52
@@ -64,7 +65,7 @@ protected function zipball($url, array $package, $path)
64
65
if (!is_dir ($ destination )) {
65
66
Storage::cpdir ($ assets , $ destination );
66
67
} else {
67
- echo PHP_EOL . $ this -> error (sprintf ('Assets already exists: %s ' , $ destination ));
68
+ echo PHP_EOL . Color:: red (sprintf ('Assets already exists: %s ' , $ destination ));
68
69
exit ;
69
70
}
70
71
}
@@ -113,12 +114,12 @@ protected function download($url, $destination)
113
114
$ type = (is_array ($ type ) && isset ($ type ['content_type ' ])) ? $ type ['content_type ' ] : '' ;
114
115
115
116
if (!is_string ($ type ) || false === strpos ($ type , 'application/zip ' )) {
116
- echo PHP_EOL . sprintf (
117
+ echo PHP_EOL . Color:: red ( sprintf (
117
118
"Error: Remote sever sending an invalid content type: '%s (%s)', expecting '%s' " ,
118
119
$ type ,
119
120
gettype ($ type ),
120
121
'application/zip '
121
- ) . PHP_EOL ;
122
+ )) ;
122
123
exit ;
123
124
}
124
125
@@ -133,17 +134,17 @@ protected function download($url, $destination)
133
134
]);
134
135
135
136
if (false === curl_exec ($ ch )) {
136
- echo PHP_EOL . $ this -> error ('Error: ' . curl_error ($ ch ));
137
+ echo PHP_EOL . Color:: red ('Error: ' . curl_error ($ ch ));
137
138
exit ;
138
139
}
139
140
140
141
curl_close ($ ch );
141
142
fclose ($ fopen );
142
143
} catch (\Throwable $ e ) {
143
- echo PHP_EOL . $ this -> error ('Error: ' . $ e ->getMessage ());
144
+ echo PHP_EOL . Color:: red ('Error: ' . $ e ->getMessage ());
144
145
exit ;
145
146
} catch (\Exception $ e ) {
146
- echo PHP_EOL . $ this -> error ('Error: ' . $ e ->getMessage ());
147
+ echo PHP_EOL . Color:: red ('Error: ' . $ e ->getMessage ());
147
148
exit ;
148
149
}
149
150
}
@@ -165,14 +166,14 @@ public static function unzip($file, $destination)
165
166
}
166
167
167
168
if (!extension_loaded ('zip ' ) || !class_exists ('\ZipArchive ' )) {
168
- echo PHP_EOL . $ this -> error ('Please enable php-zip extension on this server ' );
169
+ echo PHP_EOL . Color:: red ('Please enable php-zip extension on this server ' );
169
170
exit ;
170
171
}
171
172
172
173
$ zip = new \ZipArchive ();
173
174
174
175
if (!$ zip ->open ($ file )) {
175
- echo PHP_EOL . $ this -> error (sprintf ('Error: Could not open zip file: %s ' , $ file ));
176
+ echo PHP_EOL . Color:: red (sprintf ('Error: Could not open zip file: %s ' , $ file ));
176
177
exit ;
177
178
}
178
179
0 commit comments