Skip to content

Commit 4ad6d51

Browse files
committed
add events before actions are performed
1 parent 4a8b934 commit 4ad6d51

File tree

7 files changed

+115
-2
lines changed

7 files changed

+115
-2
lines changed

src/Events/FolderIsRenaming.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Unisharp\Laravelfilemanager\Events;
4+
5+
class FolderIsRenaming
6+
{
7+
private $path;
8+
9+
public function __construct($old_path, $new_path)
10+
{
11+
$this->old_path = $old_path;
12+
$this->new_path = $new_path;
13+
}
14+
15+
/**
16+
* @return string
17+
*/
18+
public function old_path()
19+
{
20+
return $this->old_path;
21+
}
22+
23+
public function new_path()
24+
{
25+
return $this->new_path;
26+
}
27+
28+
}

src/Events/ImageIsDeleting.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Unisharp\Laravelfilemanager\Events;
4+
5+
class ImageIsDeleting
6+
{
7+
private $path;
8+
9+
public function __construct($path)
10+
{
11+
$this->path = $path;
12+
}
13+
14+
/**
15+
* @return string
16+
*/
17+
public function path()
18+
{
19+
return $this->path;
20+
}
21+
22+
}

src/Events/ImageIsRenaming.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Unisharp\Laravelfilemanager\Events;
4+
5+
class ImageIsRenaming
6+
{
7+
private $path;
8+
9+
public function __construct($old_path, $new_path)
10+
{
11+
$this->old_path = $old_path;
12+
$this->new_path = $new_path;
13+
}
14+
15+
/**
16+
* @return string
17+
*/
18+
public function old_path()
19+
{
20+
return $this->old_path;
21+
}
22+
23+
public function new_path()
24+
{
25+
return $this->new_path;
26+
}
27+
28+
}

src/Events/ImageIsUploading.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Unisharp\Laravelfilemanager\Events;
4+
5+
class ImageIsUploading
6+
{
7+
private $path;
8+
9+
public function __construct($path)
10+
{
11+
$this->path = $path;
12+
}
13+
14+
/**
15+
* @return string
16+
*/
17+
public function path()
18+
{
19+
return $this->path;
20+
}
21+
22+
}

src/controllers/DeleteController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\File;
77
use Illuminate\Support\Facades\Input;
88
use Lang;
9+
use Unisharp\Laravelfilemanager\Events\ImageIsDeleting;
910
use Unisharp\Laravelfilemanager\Events\ImageWasDeleted;
1011

1112
/**
@@ -28,6 +29,8 @@ public function getDelete()
2829
$file_to_delete = $file_path . $name_to_delete;
2930
$thumb_to_delete = parent::getPath('thumb') . $name_to_delete;
3031

32+
Event::fire(new ImageIsDeleting($file_to_delete));
33+
3134
if (!File::exists($file_to_delete)) {
3235
return $file_to_delete . ' not found!';
3336
}
@@ -44,7 +47,7 @@ public function getDelete()
4447

4548
File::delete($file_to_delete);
4649
Event::fire(new ImageWasDeleted($file_to_delete));
47-
50+
4851
if ('Images' === $this->file_type) {
4952
File::delete($thumb_to_delete);
5053
}

src/controllers/RenameController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use Illuminate\Support\Facades\Input;
88
use Illuminate\Support\Str;
99
use Lang;
10+
use Unisharp\Laravelfilemanager\Events\ImageIsRenaming;
1011
use Unisharp\Laravelfilemanager\Events\ImageWasRenamed;
12+
use Unisharp\Laravelfilemanager\Events\FolderIsRenaming;
1113
use Unisharp\Laravelfilemanager\Events\FolderWasRenamed;
1214

1315
/**
@@ -36,6 +38,12 @@ public function getRename()
3638

3739
$new_file = $file_path . $new_name;
3840

41+
if (File::isDirectory($old_file)) {
42+
Event::fire(new FolderIsRenaming($old_file, $new_file));
43+
} else {
44+
Event::fire(new ImageIsRenaming($old_file, $new_file));
45+
}
46+
3947
if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) {
4048
return Lang::get('laravel-filemanager::lfm.error-folder-alnum');
4149
} elseif (File::exists($new_file)) {

src/controllers/UploadController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Lang;
1010
use Intervention\Image\Facades\Image;
1111
use Symfony\Component\HttpFoundation\File\UploadedFile;
12+
use Unisharp\Laravelfilemanager\Events\ImageIsUploading;
1213
use Unisharp\Laravelfilemanager\Events\ImageWasUploaded;
1314

1415
/**
@@ -45,9 +46,10 @@ public function upload()
4546
foreach($files as $file)
4647
{
4748
$new_filename = $this->getNewName($file);
48-
4949
$dest_path = parent::getPath('directory');
5050

51+
Event::fire(new ImageIsUploading($dest_path . $new_filename));
52+
5153
if (File::exists($dest_path . $new_filename)) {
5254
return Lang::get('laravel-filemanager::lfm.error-file-exist');
5355
}

0 commit comments

Comments
 (0)