8000 add commands · zerosdev/laravel-captcha@4ab6b8e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ab6b8e

Browse files
committed
add commands
1 parent f40b4c5 commit 4ab6b8e

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/Commands/Font.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public function handle()
4444
$validExt = ['ttf', 'woff', 'woff2', 'eot'];
4545

4646
if( !file_exists($fontPath) || !is_dir($fontPath) ) {
47-
return "Directory {$fontPath} is not exists or is not readable!";
10000 47+
return $this->error("Directory {$fontPath} is not exists or is not readable!");
4848
}
4949

5050
if( empty($import) )
5151
{
5252
if( ($od = opendir($fontPath)) === false ) {
53-
return "Failed to open directory: {$fontPath}";
53+
return $this->error("Failed to open directory: {$fontPath}");
5454
}
5555

5656
$files = [];
@@ -59,19 +59,37 @@ public function handle()
5959
{
6060
$originalName = $file;
6161
$loweredName = strtolower($file);
62+
$ext = pathinfo($loweredName, PATHINFO_EXTENSION);
6263

63-
if( in_array(substr($loweredName, -3), $validExt) )
64+
if( in_array($ext, $validExt) )
6465
{
6566
$files[] = $originalName;
6667
}
6768
}
6869

69-
return implode("\n", $files);
70+
$i = 1;
71+
foreach( $files as $file ) {
72+
$this->line("{$i}. ".$file);
73+
$i++;
74+
}
7075
}
7176
else
7277
{
73-
if( !in_array(substr($import, -3), $validExt) ) {
74-
return "Unsupported font format. Please use one of supported font format: " . implode(", ", $validExt);
78+
if( !filter_var($import, FILTER_VALIDATE_URL) )
79+
{
80+
if( !file_exists($import) ) {
81+
return $this->error("{$import} is not exists or is not readable!");
82+
}
83+
84+
if( !is_file($import) ) {
85+
return $this->error("{$import} is not valid file or is not readable!");
86+
}
87+
}
88+
89+
$ext = pathinfo(strtolower($import), PATHINFO_EXTENSION);
90+
91+
if( !in_array($ext, $validExt) ) {
92+
return $this->error("Unsupported font format. Please use one of supported font format: " . implode(", ", $validExt));
7593
}
7694

7795
$fileName = basename($import);
@@ -81,15 +99,15 @@ public function handle()
8199
@file_put_contents($fontPath.'/'.$fileName, $f);
82100

83101
if( !file_exists($fontPath.'/'.$fileName) || !is_file($fontPath.'/'.$fileName) ) {
84-
return "Failed to import font";
102+
return $this->error("Failed to import font");
85103
}
86104
}
87105
else
88106
{
89-
return "Failed to import font";
107+
return $this->error("Failed to import font");
90108
}
91109

92-
return "Import font success!";
110+
return $this->info("Import font success!");
93111
}
94112
}
95113
}

src/ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function boot()
2020

2121
if ($this->app->runningInConsole()) {
2222
$this->commands([
23-
ZerosDev\LaravelCaptcha\Commands\Font::class,
23+
Commands\Font::class,
2424
]);
2525
}
2626
}

0 commit comments

Comments
 (0)
0