Skip to content

Commit 317a720

Browse files
authored
Merge pull request #77 from atmonshi/l6
use Illuminate\Support\Str
2 parents 25acea7 + 88ec5c1 commit 317a720

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

src/Http/Services/DefaultNamingStrategy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Infinety\Filemanager\Http\Services;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\UploadedFile;
67

78
class DefaultNamingStrategy extends AbstractNamingStrategy
@@ -19,7 +20,7 @@ public function name(string $currentFolder, UploadedFile $file): string
1920
$filename = sprintf(
2021
'%s_%s.%s',
2122
pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME),
22-
str_random(7),
23+
Str::random(7),
2324
$file->getClientOriginalExtension()
2425
);
2526
}

src/Http/Services/FileTypesImages.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Infinety\Filemanager\Http\Services;
44

5+
use Illuminate\Support\Str;
6+
57
class FileTypesImages
68
{
79
/**
@@ -47,7 +49,7 @@ public function getImage($mime)
4749
*/
4850
private function checkMime($mime, $type)
4951
{
50-
if (str_contains($mime, $type)) {
52+
if (Str::contains($mime, $type)) {
5153
return true;
5254
}
5355

src/Http/Services/GetFiles.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use GuzzleHttp\Client;
7+
use Illuminate\Support\Str;
78
use Illuminate\Support\Facades\Storage;
89

910
trait GetFiles
@@ -234,63 +235,63 @@ public function getFileType($file)
234235
$mime = $this->storage->getMimetype($file['path']);
235236
$extension = $file['extension'];
236237

237-
if (str_contains($mime, 'directory')) {
238+
if (Str::contains($mime, 'directory')) {
238239
return 'dir';
239240
}
240241

241-
if (str_contains($mime, 'image') || $extension == 'svg') {
242+
if (Str::contains($mime, 'image') || $extension == 'svg') {
242243
return 'image';
243244
}
244245

245-
if (str_contains($mime, 'pdf')) {
246+
if (Str::contains($mime, 'pdf')) {
246247
return 'pdf';
247248
}
248249

249-
if (str_contains($mime, 'audio')) {
250+
if (Str::contains($mime, 'audio')) {
250251
return 'audio';
251252
}
252253

253-
if (str_contains($mime, 'video')) {
254+
if (Str::contains($mime, 'video')) {
254255
return 'video';
255256
}
256257

257-
if (str_contains($mime, 'zip')) {
258+
if (Str::contains($mime, 'zip')) {
258259
return 'file';
259260
}
260261

261-
if (str_contains($mime, 'rar')) {
262+
if (Str::contains($mime, 'rar')) {
262263
return 'file';
263264
}
264265

265-
if (str_contains($mime, 'octet-stream')) {
266+
if (Str::contains($mime, 'octet-stream')) {
266267
return 'file';
267268
}
268269

269-
if (str_contains($mime, 'excel')) {
270+
if (Str::contains($mime, 'excel')) {
270271
return 'text';
271272
}
272273

273-
if (str_contains($mime, 'word')) {
274+
if (Str::contains($mime, 'word')) {
274275
return 'text';
275276
}
276277

277-
if (str_contains($mime, 'css')) {
278+
if (Str::contains($mime, 'css')) {
278279
return 'text';
279280
}
280281

281-
if (str_contains($mime, 'javascript')) {
282+
if (Str::contains($mime, 'javascript')) {
282283
return 'text';
283284
}
284285

285-
if (str_contains($mime, 'plain')) {
286+
if (Str::contains($mime, 'plain')) {
286287
return 'text';
287288
}
288289

289-
if (str_contains($mime, 'rtf')) {
290+
if (Str::contains($mime, 'rtf')) {
290291
return 'text';
291292
}
292293

293-
if (str_contains($mime, 'text')) {
294+
if (Str::contains($mime, 'text')) {
294295
return 'text';
295296
}
296297

@@ -313,11 +314,11 @@ public function getThumb($file, $folder = false)
313314
$mime = $this->storage->getMimetype($file['path']);
314315
$extension = $file['extension'];
315316

316-
if (str_contains($mime, 'directory')) {
317+
if (Str::contains($mime, 'directory')) {
317318
return false;
318319
}
319320

320-
if (str_contains($mime, 'image') || $extension == 'svg') {
321+
if (Str::contains($mime, 'image') || $extension == 'svg') {
321322
if (method_exists($this->storage, 'put')) {
322323
return $this->storage->url($file['path']);
323324
}
@@ -417,7 +418,7 @@ public function accept($file)
417418
*/
418419
public function isDot($file)
419420
{
420-
if (starts_with($file['basename'], '.')) {
421+
if (Str::startsWith($file['basename'], '.')) {
421422
return true;
422423
}
423424

@@ -488,7 +489,7 @@ public function getPaths($currentFolder)
488489
*/
489490
public function recursivePaths($name, $pathCollection)
490491
{
491-
return str_before($pathCollection->implode('/'), $name).$name;
492+
return Str::before($pathCollection->implode('/'), $name).$name;
492493
}
493494

494495
/**

src/Http/Services/NormalizeFile.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ZipArchive;
77
use SplFileInfo;
88
use Carbon\Carbon;
9+
use Illuminate\Support\Str;
910
use Illuminate\Support\Collection;
1011
use Illuminate\Filesystem\FilesystemAdapter;
1112

@@ -68,25 +69,25 @@ private function setExtras(Collection $data)
6869
$mime = $this->storage->getMimetype($this->storagePath);
6970

7071
// Image
71-
if (str_contains($mime, 'image') || $data['ext'] == 'svg') {
72+
if (Str::contains($mime, 'image') || $data['ext'] == 'svg') {
7273
$data->put('type', 'image');
7374
$data->put('dimensions', $this->getDimensions($this->storage->getMimetype($this->storagePath)));
7475
}
7576

7677
// Video
77-
if (str_contains($mime, 'audio')) {
78+
if (Str::contains($mime, 'audio')) {
7879
$data->put('type', 'audio');
7980
$src = str_replace(env('APP_URL'), '', $this->storage->url($this->storagePath));
8081
$data->put('src', $src);
8182
}
8283

8384
// Video
84-
if (str_contains($mime, 'video')) {
85+
if (Str::contains($mime, 'video')) {
8586
$data->put('type', 'video');
8687
}
8788

8889
// text
89-
if ($this->availablesTextExtensions() && str_contains($mime, 'text')) {
90+
if ($this->availablesTextExtensions() && Str::contains($mime, 'text')) {
9091
$data->put('type', 'text');
9192

9293
if ($data['size']) {
@@ -100,24 +101,24 @@ private function setExtras(Collection $data)
100101
}
101102

102103
// text
103-
if (str_contains($mime, 'pdf')) {
104+
if (Str::contains($mime, 'pdf')) {
104105
$data->put('type', 'pdf');
105106
}
106107

107108
// docx
108-
if (str_contains($mime, 'wordprocessingml')) {
109+
if (Str::contains($mime, 'wordprocessingml')) {
109110
$data->put('type', 'word');
110111
// $data->put('source', $this->storage->get($this->storagePath));
111112
}
112113

113114
// zip
114-
if (str_contains($mime, 'zip')) {
115+
if (Str::contains($mime, 'zip')) {
115116
$data->put('type', 'zip');
116117
$data->put('source', $this->readZip());
117118
}
118119

119120
// // rar
120-
// if (str_contains($mime, 'rar')) {
121+
// if (Str::contains($mime, 'rar')) {
121122
// $data->put('type', 'zip');
122123
// $data->put('source', $this->readRar());
123124
// }
@@ -143,7 +144,7 @@ public function getFileSize()
143144
*/
144145
private function getImage($mime, $extension = false)
145146
{
146-
if (str_contains($mime, 'image') || $extension == 'svg') {
147+
if (Str::contains($mime, 'image') || $extension == 'svg') {
147148
return $this->storage->url($this->storagePath);
148149
}
149150

@@ -161,7 +162,7 @@ private function getDimensions($mime)
161162
return false;
162163
}
163164

164-
if (str_contains($mime, 'image')) {
165+
if (Str::contains($mime, 'image')) {
165166
[$width, $height] = getimagesize($this->storage->path($this->storagePath));
166167

167168
if (! empty($width) && ! empty($height)) {
@@ -208,7 +209,7 @@ private function availablesTextExtensions()
208209

209210
$exist = false;
210211
for ($i = 0; $i < count($types); $i++) {
211-
if (str_contains($types[$i], 'text') || str_contains($types[$i], 'plain') || str_contains($types[$i], 'sql') || str_contains($types[$i], 'javascript')) {
212+
if (Str::contains($types[$i], 'text') || Str::contains($types[$i], 'plain') || Str::contains($types[$i], 'sql') || Str::contains($types[$i], 'javascript')) {
212213
$exist = true;
213214
break;
214215
}

0 commit comments

Comments
 (0)