Skip to content

Commit f91f79c

Browse files
committed
Merge pull request #69 from ejeanneaubc/master
Add new events to manage Delete and Rename
2 parents 97c6378 + 2b23f1e commit f91f79c

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/Events/ImageWasDeleted.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 ImageWasDeleted
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/ImageWasRenamed.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 ImageWasRenamed
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/controllers/DeleteController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php namespace Unisharp\Laravelfilemanager\controllers;
22

3+
use Illuminate\Support\Facades\Event;
34
use Unisharp\Laravelfilemanager\controllers\Controller;
45
use Illuminate\Support\Facades\Config;
56
use Illuminate\Support\Facades\File;
67
use Illuminate\Support\Facades\Input;
78
use Lang;
9+
use Unisharp\Laravelfilemanager\Events\ImageWasDeleted;
810

911
/**
1012
* Class CropController
@@ -41,7 +43,8 @@ public function getDelete()
4143
}
4244

4345
File::delete($file_to_delete);
44-
46+
Event::fire(new ImageWasDeleted($file_to_delete));
47+
4548
if ('Images' === $this->file_type) {
4649
File::delete($thumb_to_delete);
4750
}

src/controllers/RenameController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php namespace Unisharp\Laravelfilemanager\controllers;
22

3+
use Illuminate\Support\Facades\Event;
34
use Unisharp\Laravelfilemanager\controllers\Controller;
45
use Illuminate\Support\Facades\Config;
56
use Illuminate\Support\Facades\File;
67
use Illuminate\Support\Facades\Input;
78
use Illuminate\Support\Str;
89
use Lang;
10+
use Unisharp\Laravelfilemanager\Events\ImageWasRenamed;
911

1012
/**
1113
* Class RenameController
@@ -37,6 +39,8 @@ public function getRename()
3739
return Lang::get('laravel-filemanager::lfm.error-rename');
3840
}
3941

42+
Event::fire(new ImageWasRenamed($old_file, $new_file));
43+
4044
if (File::isDirectory($old_file)) {
4145
File::move($old_file, $new_file);
4246
return 'OK';

0 commit comments

Comments
 (0)