@@ -44,13 +44,13 @@ public function handle()
44
44
$ validExt = ['ttf ' , 'woff ' , 'woff2 ' , 'eot ' ];
45
45
46
46
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! " ) ;
48
48
}
49
49
50
50
if ( empty ($ import ) )
51
51
{
52
52
if ( ($ od = opendir ($ fontPath )) === false ) {
53
- return "Failed to open directory: {$ fontPath }" ;
53
+ return $ this -> error ( "Failed to open directory: {$ fontPath }" ) ;
54
54
}
55
55
56
56
$ files = [];
@@ -59,19 +59,37 @@ public function handle()
59
59
{
60
60
$ originalName = $ file ;
61
61
$ loweredName = strtolower ($ file );
62
+ $ ext = pathinfo ($ loweredName , PATHINFO_EXTENSION );
62
63
63
- if ( in_array (substr ( $ loweredName , - 3 ) , $ validExt ) )
64
+ if ( in_array ($ ext , $ validExt ) )
64
65
{
65
66
$ files [] = $ originalName ;
66
67
}
67
68
}
68
69
69
- return implode ("\n" , $ files );
70
+ $ i = 1 ;
71
+ foreach ( $ files as $ file ) {
72
+ $ this ->line ("{$ i }. " .$ file );
73
+ $ i ++;
74
+ }
70
75
}
71
76
else
72
77
{
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 ));
75
93
}
76
94
77
95
$ fileName = basename ($ import );
@@ -81,15 +99,15 @@ public function handle()
81
99
@file_put_contents ($ fontPath .'/ ' .$ fileName , $ f );
82
100
83
101
if ( !file_exists ($ fontPath .'/ ' .$ fileName ) || !is_file ($ fontPath .'/ ' .$ fileName ) ) {
84
- return "Failed to import font " ;
102
+ return $ this -> error ( "Failed to import font " ) ;
85
103
}
86
104
}
87
105
else
88
106
{
89
- return "Failed to import font " ;
107
+ return $ this -> error ( "Failed to import font " ) ;
90
108
}
91
109
92
- return "Import font success! " ;
110
+ return $ this -> info ( "Import font success! " ) ;
93
111
}
94
112
}
95
113
}
0 commit comments