Skip to content

Commit b115dca

Browse files
committed
refactor: extract upload validation and add test cases
1 parent 05da8be commit b115dca

13 files changed

+354
-47
lines changed

src/Controllers/CropController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getCropimage($overWrite = true)
4747
->save($crop_path);
4848

4949
// make new thumbnail
50-
$this->lfm->makeThumbnail($image_name);
50+
$this->lfm->generateThumbnail($image_name);
5151

5252
event(new ImageWasCropped($image_path));
5353
}

src/Controllers/LfmController.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ public function getErrors()
7171
return $arr_errors;
7272
}
7373

74-
public function error($error_type, $variables = [])
75-
{
76-
return $this->helper->error($error_type, $variables);
77-
}
78-
7974
/**
8075
* Overrides settings in php.ini.
8176
*

src/Controllers/UploadController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function upload()
3333

3434
foreach (is_array($uploaded_files) ? $uploaded_files : [$uploaded_files] as $file) {
3535
try {
36+
$this->lfm->validateUploadedFile($file);
37+
3638
$new_filename = $this->lfm->upload($file);
3739
} catch (\Exception $e) {
3840
Log::error($e->getMessage(), [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class DuplicateFileNameException extends \Exception
6+
{
7+
public function __construct()
8+
{
9+
$this->message = trans('laravel-filemanager::lfm.error-file-exist');
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class EmptyFileException extends \Exception
6+
{
7+
public function __construct()
8+
{
9+
$this->message = trans('laravel-filemanager::lfm.error-file-empty');
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class ExcutableFileException extends \Exception
6+
{
7+
public function __construct()
8+
{
9+
$this->message = 'Invalid file detected';
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class FileFailedToUploadException extends \Exception
6+
{
7+
public function __construct($error_code)
8+
{
9+
$this->message = 'File failed to upload. Error code: ' . $error_code;
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class FileSizeExceedConfigurationMaximumException extends \Exception
6+
{
7+
public function __construct($file_size)
8+
{
9+
$this->message = trans('laravel-filemanager::lfm.error-size') . $file_size;
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class FileSizeExceedIniMaximumException extends \Exception
6+
{
7+
public function __construct()
8+
{
9+
$this->message = trans('laravel-filemanager::lfm.error-file-size', ['max' => ini_get('upload_max_filesize')]);
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace UniSharp\LaravelFilemanager\Exceptions;
4+
5+
class InvalidMimeTypeException extends \Exception
6+
{
7+
public function __construct($mimetype)
8+
{
9+
$this->message = trans('laravel-filemanager::lfm.error-mime') . $mimetype;
10+
}
11+
}

0 commit comments

Comments
 (0)