Skip to content

Commit a2fed31

Browse files
committed
Sync
1 parent e7d7b10 commit a2fed31

File tree

5 files changed

+56
-32
lines changed

5 files changed

+56
-32
lines changed

system/console/color.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace System\Console;
4+
5+
defined('DS') or exit('No direct access.');
6+
7+
class Color
8+
{
9+
public static function supported()
10+
{
11+
if (DS === '\\') {
12+
return (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT))
13+
|| (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON');
14+
}
15+
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
16+
}
17+
18+
public static function green($text, $newline = true)
19+
{
20+
$text = static::supported() ? "\033[32m{$text}\033[m" : $text;
21+
return $text . ($newline ? PHP_EOL : '');
22+
}
23+
24+
public static function yellow($text, $newline = true)
25+
{
26+
$text = static::supported() ? "\033[33m{$text}\033[m" : $text;
27+
return $text . ($newline ? PHP_EOL : '');
28+
}
29+
30+
public static function red($text, $newline = true)
31+
{
32+
$text = static::supported() ? "\033[31m{$text}\033[m" : $text;
33+
return $text . ($newline ? PHP_EOL : '');
34+
}
35+
}

system/console/commands/command.php

+3-15
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,18 @@
88

99
abstract class Command
1010
{
11-
private function supported()
12-
{
13-
if (DS === '\\') {
14-
return (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT))
15-
|| (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON');
16-
}
17-
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
18-
}
19-
2011
protected function info($text, $newline = true)
2112
{
22-
$text = $this->supported() ? "\033[32m{$text}\033[m" : $text;
23-
return $text . ($newline ? PHP_EOL : '');
13+
return Color::green($text, $newline);
2414
}
2515

2616
protected function warning($text, $newline = true)
2717
{
28-
$text = $this->supported() ? "\033[33m{$text}\033[m" : $text;
29-
return $text . ($newline ? PHP_EOL : '');
18+
return Color::yellow($text, $newline);
3019
}
3120

3221
protected function error($text, $newline = true)
3322
{
34-
$text = $this->supported() ? "\033[31m{$text}\033[m" : $text;
35-
return $text . ($newline ? PHP_EOL : '');
23+
return Color::red($text, $newline);
3624
}
3725
}

system/console/commands/package/providers/provider.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
defined('DS') or exit('No direct access.');
66

77
use System\Storage;
8+
use System\Console\Color;
89

910
abstract class Provider
1011
{
@@ -36,16 +37,16 @@ protected function zipball($url, array $package, $path)
3637
}
3738

3839
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']));
4041
exit;
4142
}
4243

4344
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);
4546
$this->download($url, $zipball);
4647
echo ' done!';
4748

48-
echo PHP_EOL . $this->info('Extracting zipball...', false);
49+
echo PHP_EOL . Color::green('Extracting zipball...', false);
4950

5051
static::unzip($zipball, path('package'));
5152

@@ -64,7 +65,7 @@ protected function zipball($url, array $package, $path)
6465
if (!is_dir($destination)) {
6566
Storage::cpdir($assets, $destination);
6667
} 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));
6869
exit;
6970
}
7071
}
@@ -113,12 +114,12 @@ protected function download($url, $destination)
113114
$type = (is_array($type) && isset($type['content_type'])) ? $type['content_type'] : '';
114115

115116
if (!is_string($type) || false === strpos($type, 'application/zip')) {
116-
echo PHP_EOL . sprintf(
117+
echo PHP_EOL . Color::red(sprintf(
117118
"Error: Remote sever sending an invalid content type: '%s (%s)', expecting '%s'",
118119
$type,
119120
gettype($type),
120121
'application/zip'
121-
) . PHP_EOL;
122+
));
122123
exit;
123124
}
124125

@@ -133,17 +134,17 @@ protected function download($url, $destination)
133134
]);
134135

135136
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));
137138
exit;
138139
}
139140

140141
curl_close($ch);
141142
fclose($fopen);
142143
} catch (\Throwable $e) {
143-
echo PHP_EOL . $this->error('Error: ' . $e->getMessage());
144+
echo PHP_EOL . Color::red('Error: ' . $e->getMessage());
144145
exit;
145146
} catch (\Exception $e) {
146-
echo PHP_EOL . $this->error('Error: ' . $e->getMessage());
147+
echo PHP_EOL . Color::red('Error: ' . $e->getMessage());
147148
exit;
148149
}
149150
}
@@ -165,14 +166,14 @@ public static function unzip($file, $destination)
165166
}
166167

167168
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');
169170
exit;
170171
}
171172

172173
$zip = new \ZipArchive();
173174

174175
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));
176177
exit;
177178
}
178179

system/console/commands/package/publisher.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use System\Storage;
88
use System\Package;
9+
use System\Console\Color;
910

1011
class Publisher
1112
{
@@ -19,26 +20,26 @@ class Publisher
1920
public function publish($package)
2021
{
2122
if (!Package::exists($package)) {
22-
echo 'Package is not registered: ' . $package;
23+
echo Color::red('Package is not registered: ' . $package);
2324
return;
2425
}
2526

2627
$source = path('package') . $package . DS . 'assets';
2728
$destination = path('assets') . 'packages' . DS . $package;
2829

2930
if (!is_dir($source)) {
30-
echo $this->error('Package does not caontains any assets!');
31+
echo Color::red('Package does not caontains any assets!');
3132
return;
3233
}
3334

3435
if (is_dir($destination)) {
35-
echo $this->error('Package assets already published!');
36+
echo Color::red('Package assets already published!');
3637
return;
3738
}
3839

3940
Storage::cpdir($source, $destination);
4041

41-
echo $this->info('Assets published for package: ' . $package);
42+
echo Color::green('Assets published for package: ' . $package);
4243
}
4344

4445
/**
@@ -54,6 +55,6 @@ public function unpublish($package)
5455
Storage::rmdir($destination);
5556
}
5657

57-
echo $this->info('Assets deleted for package: ' . $package);
58+
echo Color::green('Assets deleted for package: ' . $package);
5859
}
5960
}

system/database/facile/query.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
defined('DS') or exit('No direct access.');
66

77
use System\Str;
8-
use System\Arr;
98
use System\Database;
109

1110
class Query

0 commit comments

Comments
 (0)